Home   Help Search Login Register  

Author Topic: Initialising a global variable.  (Read 1856 times)

0 Members and 1 Guest are viewing this topic.

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Initialising a global variable.
« on: 05 Sep 2009, 20:09:50 »
OK, so in my Fire & Smoke addon, I'm implementing a maximum concurrent fires limit. Lets say that limit is 100, starting from 0, and that the variable I'll use will be called JTD_CurrentFires. The addon itself is driven by eventhandlers, so there is no single-run script where I can initialise global variables.

(If anyone knows how I CAN run an initialisation script from a config, that will be the best method BTW.)

So, how DO I initialise a global variable in this case? In the config I've tried:
Code: [Select]
JTD_CurrentFires = 0; but that doesn't seem to work on its own, and so in the script I've tried:
Code: [Select]
JTD_CurrentFires = getNumber(configFile >> "JTD_FireTrees");but all that does is set the number back to 0 every time, as you would expect :)

?
« Last Edit: 05 Sep 2009, 21:18:37 by DMarkwick »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Initialising a global variable.
« Reply #1 on: 05 Sep 2009, 20:41:21 »
Code: [Select]
if (isNil "JTD_CurrentFires") then {JTD_CurrentFires = getNumber(configFile >> "JTD_FireTrees")};
Should initialize JTD_CurrentFires in the script (once). Then just add and remove from that number as you desire, I guess!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re: Initialising a global variable.
« Reply #2 on: 05 Sep 2009, 23:39:08 »
Thanks :)