Adding to GlobalInts -SOLVED

Started by Kinoko, Thu 15/07/2004 07:50:32

Previous topic - Next topic

Kinoko

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.

Gilbert

Yes.

For example to add something:

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

I think you can get the idea easily and do other stuffs similarly.

Radiant

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;
   ...
}

Kinoko

Thanks guys ^_^ Well, they both seem like good solutions, I'm not sure which one I should use.

SMF spam blocked by CleanTalk