Jump to content
Sign in to follow this  
fusion13

Better way?

Recommended Posts

Hello all I was wondering if there was a way, I can do this without all of the if statements

fishget = [1, 2, 3] call BIS_fnc_selectRandom;
fish = fish + fishget;
if (weight >= maxweight) then {
player globalChat "You have reached the maximum weight";
} else {
if (fishget == 1) then {
	weight = weight + 2;
} else {
	if (fishget == 2) then {
		weight = weight + 4;
	} else {
		if (fishget == 3) then {
			weight = weight + 6;
		};
	};
};
};
hint format ["You have goten %1 fish, you know have %2 fish", fishget, fish];

Also I have weight = 0; declared in a var file along with maxweight = 60;

Thanks,

Fusion

:dancehead:

Share this post


Link to post
Share on other sites

Since you are comparing a few items the performance gain is minimal.

fishget = [1, 2, 3] call BIS_fnc_selectRandom;
fish = fish + fishget;
if (weight >= maxweight) then 
{
   player globalChat "You have reached the maximum weight";
} 
else 
{
if(fishget != 2) then 
{
	if(fishget < 2) then
	{
		weight = weight + 2;
	}
	else
	{
		weight = weight + 6;
	};
}
else
{
	weight = weight + 4;
};
};
hint format ["You have caught %1 fish, you now have %2 fish", fishget, fish]; 

What I have done here is basically started the search in the middle instead at the beginning. This way if fishget is equal to 3, it will only take 2 comparison rather than 3 to get to case 3. Now if fishget is not 2 well it has to be 1 or 3 since we know the range is between 1 and 3.

Edited by Johnson11B2P
Forgot one line.

Share this post


Link to post
Share on other sites
fishget = [1, 2, 3] call BIS_fnc_selectRandom; 
fish = fish + fishget; 
if (weight >= maxweight) then { 
   player globalChat "You have reached the maximum weight"; 
} else { 
switch (fishget) do {
 case 1:
 {
 weight = + 2;
 };
 case 2:
 {
 weight = + 4;
 };
 case 3:
 {
 weight = + 6;
 };
};
}; 
hint format ["You have goten %1 fish, you know have %2 fish", fishget, fish];  

Share this post


Link to post
Share on other sites
fishget = [1, 2, 3] call BIS_fnc_selectRandom; 
fish = fish + fishget; 
if (weight >= maxweight) then { 
   player globalChat "You have reached the maximum weight"; 
} else { 
switch (fishget) do {
 case 1:
 {
 weight = + 2;
 };
 case 2:
 {
 weight = + 4;
 };
 case 3:
 {
 weight = + 6;
 };
};
}; 
hint format ["You have goten %1 fish, you know have %2 fish", fishget, fish];  

Not working with the weight, It won't prompt me the max weight line at 100+ (used to be around 50 but for some reason kept going.)

Here is my most updated script because I worked on it lastnight a bit

if (fishingsupplies == 1) then {
fishget = [1, 2, 3] call BIS_fnc_selectRandom;
fish = fish + fishget;
if (weight >= maxweight) then {
	player globalChat "You have reached the maximum weight";
};
if (weight < maxweight) then {
	if (fishget == 1) then {
		weight = weight + 2;
	};
	if (fishget == 2) then {
		weight = weight + 4;
	};
	if (fishget == 3) then {
		weight = weight + 6;
	};
};
} else {
hint "You don't have any supplies for fishing!";
};

using old method*******************

Share this post


Link to post
Share on other sites

I don't quite understand what you mean,

I have

weight = weight + 6;

So please expand on what you mean :D

Share this post


Link to post
Share on other sites

Not what your looking for but can you use:

weight += 6;

instead of:
weight = weight + 6;

New to arma scripting and did not see this in the operators list.

Share this post


Link to post
Share on other sites

+= doesn't actually work in SQF. = + does as far as I understand though. But yeah Fusion, I was under the impression you used = + instead of weight = weight +.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×