Author Topic: Global Variables in a Mod  (Read 1230 times)

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Global Variables in a Mod
« Reply #30 on: November 07, 2013, 07:14:23 pm »


               There are boolean operators in C that evaluate to true or false like == or <.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Global Variables in a Mod
« Reply #31 on: November 07, 2013, 07:27:43 pm »


               

Groove Widdit wrote...

There are boolean operators in C that evaluate to true or false like == or <.


Yes, but in NWScript TRUE (1) and FALSE (0) are both integers.  Thus commands like if(), while(), etc. take on an integer value for their argument, checking to see if that integer is 0 or not.  Using if(x == TRUE) can be problematic as it will check specifically for the value of 1 and not all non-zero integers as would be the case with if(x).  
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Global Variables in a Mod
« Reply #32 on: November 08, 2013, 03:22:43 am »


               

MagicalMaster wrote...

The default for a local variable is 0.  I admit I'm not sure if there's a difference between deleting and setting it to 0 in the fine details but from your perspective in this case they are the same.


There is a difference, yes. Deleting them clears them from memory. Having vars set to 0 uses memory. Easy to see if you store a bunch of variables on an item in the toolset - it also increases file size, whether set to 0 (or "") or something else.

Funky
               
               

               
            

Legacy_MagicalMaster

  • Hero Member
  • *****
  • Posts: 2712
  • Karma: +0/-0
Global Variables in a Mod
« Reply #33 on: November 09, 2013, 07:31:15 pm »


               

FunkySwerve wrote...

There is a difference, yes. Deleting them clears them from memory. Having vars set to 0 uses memory. Easy to see if you store a bunch of variables on an item in the toolset - it also increases file size, whether set to 0 (or "") or something else.


Good to know.  How significant is the process of actually allocating the memory?  In other words, if I'm going to change a variable from 0 to 1 to 0 to 1 and do this every 30 seconds, am I better off changing the value or deleting it?