Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 17/04/2003 16:24:40

Title: Can't add value to a global int.
Post by: on Thu 17/04/2003 16:24:40
  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
Title: Re: Can't add value to a global int.
Post by: Jimi on Thu 17/04/2003 16:31:30
do you get an error? If so, what does it say?

try this:

else if (button==5) {
  SetGlobalInt(2+=5);
  }
Title: Re: Can't add value to a global int.
Post by: on Thu 17/04/2003 16:52:22
 I tried that and I got this error:
 Parse error in expr near '2'
Title: Re: Can't add value to a global int.
Post by: RickJ on Thu 17/04/2003 16:58:31
Try this....

  SetGlobalInt (2,GetGlobalInt(2)+5);
Title: Re: Can't add value to a global int.
Post by: on Thu 17/04/2003 18:05:34
  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.
Title: Re: Can't add value to a global int.
Post by: Proskrito on Thu 17/04/2003 18:31:31
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);
Title: Re: Can't add value to a global int.
Post by: DinghyDog on Thu 17/04/2003 23:11:43
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

Title: Re: Can't add value to a global int.
Post by: Gilbert on Tue 22/04/2003 04:46:57
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.
Title: Re: Can't add value to a global int.
Post by: BlackBaron on Wed 23/04/2003 21:22:17
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.
Title: Re: Can't add value to a global int.
Post by: BlackBaron on Wed 23/04/2003 21:33:54
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  ;))