I'm trying to make the game so that every time you hit a button on a GUI it adds 5 to globalInt 2. This is how I have it scripted.
else if (button == 5) {
SetGlobalInt ((2),+=5);
Ive never tried this before and I can't seem to get it to work. :P
do you get an error? If so, what does it say?
try this:
else if (button==5) {
SetGlobalInt(2+=5);
}
I tried that and I got this error:
Parse error in expr near '2'
Try this....
SetGlobalInt (2,GetGlobalInt(2)+5);
Okay I set the script up like you said Rick but its not doing what I want it too.
I am making a RPG and at the beginning I want the player to be able to distribute a set amount of points into there characters abilities. So when you hit a button on the GUI it changes the value of the stat. by 5 and then transfers the amount to the character stat GUI.
By the way it compiles the script fine the way I have it, it just dosent do what I thought it would.
if your amount of points to be distributed is globalint 1(example), you could try:
SetGlobalInt (1,GetGlobalInt(1)-5);
SetGlobalInt (2,GetGlobalInt(2)+5);
If that doesn't work, try:
SetGlobalInt (1,((GetGlobalInt(1))-=5))
It's a little heavy on the parentheses, but you never know, that could be the problem. :P
-DD
No, I wonder if that line really works, as GetGlobalInt(1) is a returned value, not a variable, attempt to assign a value (eg -=5) may cause unexpectable results, if you didn't get an error or a crash first.
Just use what Proskrito wrote.
Try this,
int temp_var;
temp_var = GetGlobalInt(2)) + 5;
SetGlobalInt (2,temp_var);
If you also want to increase the other global variable (1 for example) add this right after:
temp_var = GetGlobalInt(1)) - 5;
SetGlobalInt (1,temp_var);
Please say if it works or if it gives you any errors.
Just in case you don't know (or anyone else who reads this post, for that matter), you put the
int tamp_var just once per function and is advisable that you put it at the beginning of the function.
(You probably already knew that, I just wanted to make sure ;))