Author Topic: The Value of False  (Read 484 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
The Value of False
« on: January 27, 2013, 01:30:43 am »


               In nwn - what is the value 'FALSE' equal to in terms of int value?

I just checked my nwnx database, and I see things like skill levels which I set/change according to ingame events, reading as values like 2434.

Is False  = to 2434?

Its just a little worrying.

Im going back now, putting in validation to control the upper and lower limits of my skill and ability point gain system - for extra security.
And changing all instances of
SetPersistentInt(oPC,"",FALSE);

to be
SetPersistentInt(oPC,"",0);
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
The Value of False
« Reply #1 on: January 27, 2013, 03:03:35 am »


               FALSE is defined in nwscript.nss as 0, so the two statements should be equivalent.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
The Value of False
« Reply #2 on: January 27, 2013, 07:35:29 pm »


               SM is correct, FALSE is 0 in nwscript. Makes for a lot of convenient shortcuts and simplifications. You never have to do an if(GetSomething == TRUE), for example - one of the most common unnecessary chunks of code I see. You can simply say if(GetSomething) - so long as the GetSomething function is set up to return 0 for FALSE, like most of bioware's functions. Likewise, if(!GetSomething), instead of if (GetSomething == FALSE). I could list a lot more, but I think that shows what I'm talking about.

Oh, it's worth mentioning that setting an int to 0 is NOT the same as deleting it in terms of memory - it will still be read as not set, if it's an int in scripts (doing a GetLocalInt on a nonexistent int returns 0), but there will still be space reserved for it in memory (and, depending on where it is, potentially in a bic file, as well).

Funky
               
               

               


                     Modifié par FunkySwerve, 27 janvier 2013 - 07:37 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
The Value of False
« Reply #3 on: January 27, 2013, 07:42:45 pm »


               

FunkySwerve wrote...

SM is correct, FALSE is 0 in nwscript. Makes for a lot of convenient shortcuts and simplifications. You never have to do an if(GetSomething == TRUE), for example - one of the most common unnecessary chunks of code I see. You can simply say if(GetSomething) - so long as the GetSomething function is set up to return 0 for FALSE, like most of bioware's functions. Likewise, if(!GetSomething), instead of if (GetSomething == FALSE). I could list a lot more, but I think that shows what I'm talking about.

Funky

correct, though is important to not mix up if(GetSomething == TRUE) and if(GetSomething)

TRUE is an integer constant equal to 1, this first case returns true only when GetSomething equal to 1, while second expression returns true everytime the GetSomething does not equal to 0

Conclusion: there is an engine true value that is not defined as constant
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
The Value of False
« Reply #4 on: January 27, 2013, 07:51:28 pm »


               

ShaDoOoW wrote...

Conclusion: there is an engine true value that is not defined as constant


Close.   more accurate is that there is a Compiler Text Literal constatnt for TRUE defined as 1.   Outside of that the engine never checks for TRUE cases. It only checks for FALSE, In which case it simply skips the TRUE clause.  If it is not FALSE no Jump takes place and execution falls through to the TRUE case tht was never checked for, IT is simply TRUE because it was not FALSE.
               
               

               


                     Modifié par Lightfoot8, 27 janvier 2013 - 07:52 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
The Value of False
« Reply #5 on: January 28, 2013, 08:10:51 pm »


               Lightfoot's way of explaining this is much closer to what I meant. When I said that the shortcut I was describing would only work ' so long as the GetSomething function is set up to return 0 for FALSE', it was because any nonzero value gets interpreted as 'true', be it positive or negative. TRUE, by contrast, is defined as 1 in nwscript, but there's no reason to restrict yourself to that value. For example,

    if (GetLocalInt(oArea, "DespawnTime"))
        return TRUE;
Would return TRUE for any nonzero value DespawnTime is set to, saving you from doing != 0. You could not do the same with == TRUE, because that would only return TRUE if DespawnTime was set to 1.

Funky
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
The Value of False
« Reply #6 on: January 29, 2013, 02:02:55 pm »


               This actually ended up being a SQL Statement issue.

I added a system that allowed kills of certain players to increment an Energy counter in the database.
However - I spent all my attention on getting it to target the correct player, and character

eg - Player and Tag fields - in the pwdata table, that I forgot to set the NAME field to be the 'ENERGY_STORED' name - in the query.

So - every 5 minutes - 1/4 of the xp gain from a player, was being transferred, and incrementing the int values of every database entry for specific player/characters.


The only reason I thought this might be related to False - was because I am aware of certain Constants in nwscript that instead of being equal to 0  are equal to something like 65643 or something like that

Cant remember the exact constant, but it was something like
OBJECT_INVALID, or some Constant that denotes a negative or unsuccessful attempt to do something. Cant be arsed looking it up. Lol