Can't add value to a global int.

Started by Leroy, Thu 17/04/2003 16:24:40

Previous topic - Next topic

Leroy

  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

Jimi

do you get an error? If so, what does it say?

try this:

else if (button==5) {
  SetGlobalInt(2+=5);
  }

Leroy

 I tried that and I got this error:
 Parse error in expr near '2'

RickJ

Try this....

  SetGlobalInt (2,GetGlobalInt(2)+5);

Leroy

  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.

Proskrito

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);

DinghyDog

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

It's yer owld pal Dinghy Dog!!

Gilbert

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.

BlackBaron

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.
"Do you thirst for knowledge no matter the cost?"
            -Watrik, master glassblower

BlackBaron

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  ;))
"Do you thirst for knowledge no matter the cost?"
            -Watrik, master glassblower

SMF spam blocked by CleanTalk