Jump to content
Sign in to follow this  
ra1n0fpa1n

Creating a Variable With a Value then add/subtract

Recommended Posts

Having quite a bit of trouble making variable that contains a value that i could add and subtract to, im mainly using this as a point system to determine if a player is advanced enough to unlock certain features Within the mission.

for example ive created a variable in the init.sqf

_PlayerCoins = 0;

as i understand to add and subtract i need to do

Playercoins =_x+1;

or

Playercoins =_x-1;

then i would have a script where you where two conditions would need to be met in order to activate the script

here is my example

_user = _this select 1;
		if ((count units group _user >= 10) and (PlayerCoins <5)) then 
		{
			player groupchat "You Cannot Have Anymore Units At This Time"; player removeAllActions PlayerUI;
		} else {
NumberOfUnits = 1;
execVM "MainSpawner.sqf";
		};

Somewhere along those lines i messed up because it ignores the second condition and does not display You Cannot Have Anymore Units At This Time in the sidechat , i know i am doing something wrong but i am not sure what

Share this post


Link to post
Share on other sites

hi

Properly defined private variable:

private "_myPrivateVariableName";

_myPrivateVariableName = something;

Properly defined global variable:

TAG_myPrivateVariableName = something;

Diference:

script1.sqf

private "_myPrivateVariableName";

_myPrivateVariableName = something;

TAG_myGlobalVariableName = something;

execVM "script2.sqf";

script2.sqf

private "_anotherPrivateVariableName";

[color="#FF0000"]_anotherPrivateVariableName = _myPrivateVariableName;[/color] // error, _myPrivateVariableName was private variable of script1
[color="#008000"]_anotherPrivateVariableName = TAG_myGlobalVariableName;[/color] // works, because TAG_myGlobalVariableName is global variable

[color="#FF0000"]TAG_anotherGlobalVariableName = _myPrivateVariableName;[/color] // error, _myPrivateVariableName was private variable of script1
[color="#008000"]TAG_anotherGlobalVariableName = TAG_myGlobalVariableName;[/color] // works, because TAG_myGlobalVariableName is global variable

add 1

variable = variable + 1; 

string + string

string = "something";
add = " something else";

string = string + add;

string + number

string = "something";

string2 = string + str 1;

if without additional brackets

if (myVar1 > 0 && myVar2 >2) then

myVar3 = true;

if myVar3 then

Share this post


Link to post
Share on other sites

just like to say i have recently made a mission in which all that i put in the init file was

i = 1;

and i was able to reference that throughout my mission.

you can then just put

i = i ++;

in your scripts

Share this post


Link to post
Share on other sites
i = 1;

and i was able to reference that throughout my mission.

if is that reaction on 'TAG_'

my reaction is:

i always suppose that my code will be used by somebody else...

Share this post


Link to post
Share on other sites

you can then just put

i = i ++;

in your scripts

no you can't

you have to use i = i + 1 or you get error.

Share this post


Link to post
Share on other sites
if is that reaction on 'TAG_'

my reaction is:

i always suppose that my code will be used by somebody else...

dont understand?

---------- Post added at 01:49 ---------- Previous post was at 01:48 ----------

no you can't

you have to use i = i + 1 or you get error.

ah yeah thats right

i = i + 1

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  

×