Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Kinoko on Thu 15/07/2004 07:50:32

Title: Adding to GlobalInts -SOLVED
Post by: Kinoko on Thu 15/07/2004 07:50:32
Is it possible to add/subtract/etc a particular value to/from a GlobalInt? Say HP in my game was GlobalInt #5, and I want to add whatever the current value of (int) mondmg is.

Currently, I'm using simple integers to simulate battles in my game, but the problem is that they keep resetting everytime the code for losing/gaining HP is used. I know why this is, but no good work around. I'm not sure if ints can be stored globally or not. Either way, if the GlobalInt thing works, that'll solve my problems.
Title: Re: Adding to GlobalInts
Post by: Gilbert on Thu 15/07/2004 08:17:54
Yes.

For example to add something:

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

I think you can get the idea easily and do other stuffs similarly.
Title: Re: Adding to GlobalInts
Post by: Radiant on Thu 15/07/2004 12:15:47
The alternative is to not use a GlobalInt, but declare an int globally.
I.e. at the top of your global script, put 'int thingy'.
At the bottom of your global script, put 'export thingy'.
In your global header, put 'import int thingy'.

I'm assuming that your regular ints are reset because you've declared them inside the function?
Try
int health;
function ChangeHealth () { ... }

rather than
function ChangeHealth () {
  int health;
   ...
}
Title: Re: Adding to GlobalInts
Post by: Kinoko on Thu 15/07/2004 14:18:23
Thanks guys ^_^ Well, they both seem like good solutions, I'm not sure which one I should use.