View previous topic :: View next topic |
Author |
Message |
Lugoun
Joined: 18 May 2007 Posts: 36
|
Posted: Fri Jun 01, 2007 1:57 Post subject: Boolean True/False in GetPersistentInt and SetPersistentInt |
|
|
Can we use NWN script style TRUE and FALSE when Setting and Getting Persistent Int's?
For example will this work?
SetPersistentInt(oPC, "Stuff", TRUE);
Or, do I have to do:
SetPersistentInt(oPC, "Stuff", 1);
Thanks,
Lug _________________ Lugoun
www.hotta-rpg.org |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Fri Jun 01, 2007 4:33 Post subject: |
|
|
Yes. TRUE/FALSE are just int constants behind the scenese in nwscript. _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Fri Jun 01, 2007 5:48 Post subject: |
|
|
But remember TRUE = 0
So you can get some non-true true results if the variable is NOT set.
This is why you see a lot of code "if (!false)", true if not set OR =0.
Cheers
Gryphyn |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Fri Jun 01, 2007 9:25 Post subject: |
|
|
Gryphyn wrote: | But remember TRUE = 0
|
Hmm? _________________ Papillon |
|
Back to top |
|
|
Grinning Fool
Joined: 12 Feb 2005 Posts: 264
|
Posted: Fri Jun 01, 2007 20:41 Post subject: |
|
|
Gryphyn wrote: | But remember TRUE = 0
|
Alright, you lost me with that one. _________________ Khalidine, a NWN2 persistent world
Looking for volunteers. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Jun 02, 2007 1:11 Post subject: |
|
|
Code: | if (GetLocalInt(obj,"name")) |
returns true if the local "name" is not set OR the value of the local "name" = 0
So when testing for the condition 'true' you need to know if it's because "name" has been set, or the default (0) is being used.
Cheers
Gryphyn |
|
Back to top |
|
|
Lugoun
Joined: 18 May 2007 Posts: 36
|
Posted: Sat Jun 02, 2007 2:16 Post subject: |
|
|
Cool, thanks for the reminder that the TRUE/FALSE is really just a constant int and verifying I can stick to my old habits
Hmm, I pretty much just use this:
if(GetLocalInt(obj, "name") == FALSE)
when testing to see if an int has not been set or is equal to 0. Usually for a 'do once' or a 'turn on/turn off' situation.
I can see how it would be easy leave the '== FALSE' off and not get the result you expected. _________________ Lugoun
www.hotta-rpg.org |
|
Back to top |
|
|
FunkySwerve
Joined: 02 Jun 2005 Posts: 377
|
Posted: Sat Jun 02, 2007 2:32 Post subject: |
|
|
Nwscript defaults to FALSE (0) not TRUE (nonzero) for nonset local ints, and 1 is TRUE. Unless you are talking about something else?
Funky |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Sat Jun 02, 2007 5:35 Post subject: |
|
|
FunkySwerve wrote: | Nwscript defaults to FALSE (0) not TRUE (nonzero) for nonset local ints, and 1 is TRUE. Unless you are talking about something else?
Funky |
Sorry Folks, True=1, False=0 in NWScript.
Just a little confused with all other languages I've been dealing with recently.
--but my point was "watch out for the 'not-set' trap." just in case it makes a difference to your condition checking.
Cheers
Gryphyn
*I'll shut-up now |
|
Back to top |
|
|
|