Declaring boolean variables

Post » Sun Oct 17, 2010 8:00 pm

Is the bool data type currently supported in the CS language,if not,are there any plans to add it on future OBSE versions?
User avatar
Emmanuel Morales
 
Posts: 3433
Joined: Sat Oct 06, 2007 2:03 pm

Post » Mon Oct 18, 2010 3:40 am

Use 'short'.
I believe you can then test it like boolian.
Its easy enough to test...

short myBbegin gameMode   if myB == 0      set myB to 1   endif   if myB      messagebox "Boolian works"      set myB to 2   endifend

User avatar
Tanika O'Connell
 
Posts: 3412
Joined: Fri Jan 26, 2007 1:34 am

Post » Mon Oct 18, 2010 8:11 am

Use 'short'.
I believe you can then test it like boolian.
Its easy enough to test...

short myBbegin gameMode   if myB == 0      set myB to 1   endif   if myB      messagebox "Boolian works"      set myB to 2   endifend



Willie - will myB always be initialized as exactly 0 or is there a chance that since it is actually a short there may be some rounding error that would cause == 0 to return false and therefore break the check ?? (just asking because when using shorts instead of bools you usually have to use < or >= instead of == to avoid rounding errors breaking your checks ) ie. for false you'd check < 1 and for positive check >= 1

--- and wouldn't your code snippet also create problems since you are setting myB to 2 which should invalid for a boolean ?
User avatar
Rachel Briere
 
Posts: 3438
Joined: Thu Dec 28, 2006 9:09 am

Post » Mon Oct 18, 2010 12:39 am

Shorts are exact - I think you're thinking of floats. Shorts are always initialized as 0. They are integers, so there's no fractional component that could lead to imprecision. That's why there is no Boolean defined by OBSE - it's not necessary.

Oblivion only treats 0 as false. Anything greater than 0 is true, so Willie's script is fine. It allows for more complex options than just true and false.
User avatar
gemma king
 
Posts: 3523
Joined: Fri Feb 09, 2007 12:11 pm

Post » Sun Oct 17, 2010 9:17 pm

1. Its a "test" to see if a short will evaluate as a boolian. That is why I use the 'If myB' with no other condition checks on it.

2. Since its a test only, I only want it to happen once, not an infininte loop. So I set the 'short' to 2 so it only does it once. Setting the value in the variable would be up to the programmer to ensure it is either 0 or 1.

3. All variables are exactly '0.0000' when a script first runs. I have never tested a short to see if it rounds up or down, or if it just truncates the decimal positions with no rounding.

4. When you use a short, you never have to worry about the < or > checks since the decimal positions are not kept. So, if I move 1.3 to myB, a check for myB == 1 will return true since its 'stored' value will be '1.0000', not '1.3000'. You only need the < or > if you are testing for a range of whole numbers. Such as <= 5 which would check for a value less than 6.

5. For false checks, you can use 'else'.
if myB   messagebox "true check"else   messagebox "false check"endif


But, I have not tested if a short will behave like a boolian, so this might all be a mute point.
User avatar
Pat RiMsey
 
Posts: 3306
Joined: Fri Oct 19, 2007 1:22 am

Post » Mon Oct 18, 2010 5:52 am

Shorts are exact - I think you're thinking of floats. Shorts are always initialized as 0. They are integers, so there's no fractional component that could lead to imprecision. That's why there is no Boolean defined by OBSE - it's not necessary.

Oblivion only treats 0 as false. Anything greater than 0 is true, so Willie's script is fine. It allows for more complex options than just true and false.


You are right was thinking of floats !
User avatar
Liv Staff
 
Posts: 3473
Joined: Wed Oct 25, 2006 10:51 pm

Post » Mon Oct 18, 2010 9:12 am

2. Since its a test only, I only want it to happen once, not an infininte loop. So I set the 'short' to 2 so it only does it once. Setting the value in the variable would be up to the programmer to ensure it is either 0 or 1.


As said, "IF myB" evaluates as false if myB = 0. If myB is anything else, positive or negatve, integer or fractionary, "IF myB" evaluates as true.
The above is true whether myB is a short, a float, a ref, a string_var or an array_var.

Willie, note that setting myB to 2 will make your second IF evaluate as true and the message will be shown every frame.
User avatar
Mrs shelly Sugarplum
 
Posts: 3440
Joined: Thu Jun 15, 2006 2:16 am

Post » Sun Oct 17, 2010 10:26 pm

As said, "IF myB" evaluates as false if myB = 0. If myB is anything else, positive or negatve, integer or fractionary, "IF myB" evaluates as true.
The above is true whether myB is a short, a float, a ref, a string_var or an array_var.

Willie, note that setting myB to 2 will make your second IF evaluate as true and the message will be shown every frame.


Yes very true, but JDFan was worried about using == to compare to a specific value. I was saying that shorts are the best types to use for that. I use if (array_var) all the time to test for an array being populated, as you point out.
User avatar
Nice one
 
Posts: 3473
Joined: Thu Jun 21, 2007 5:30 am

Post » Mon Oct 18, 2010 6:23 am

Willie, note that setting myB to 2 will make your second IF evaluate as true and the message will be shown every frame.

Perhaps you could explain that since this should only display the message once.

short myB begin gameMode    if myB == 0       set myB to 1    endif    if myB       messagebox "Boolian works"       set myB to 2    endif end

User avatar
Ashley Tamen
 
Posts: 3477
Joined: Sun Apr 08, 2007 6:17 am

Post » Mon Oct 18, 2010 7:32 am

Perhaps you could explain that since this should only display the message once.

short myB begin gameMode    if myB == 0       set myB to 1    endif    if myB       messagebox "Boolian works"       set myB to 2    endif end



Since it is running in game mode each frame it will be run and the way you have it set the second "If myB" test will always be true "since that test is true if myB is anything other than 0 and you have set ti to 2 so the test passes on each frame and thus it prints Boolean works and resets myB to 2 again for the next frame !! IF you want it just once it would have to set a Doonce variable also so that part of the script only runs the one time ! -- (As is you have created an infinite loop that will spam the display once every frame since if myB is 0 then it gets set to 1 and prints and sets myB to 2 so on subsequent passes If myB is true so it prints again !)
User avatar
Charlotte X
 
Posts: 3318
Joined: Thu Dec 07, 2006 2:53 am

Post » Mon Oct 18, 2010 1:22 am

Okay, I thought it tested for 1 true, not 0 (other) false.

This will test the boolian...
The first 'IF' is not tested true until myB is equal to anything but '1'. Since its initialized at 0, nothing happens until the player 'activates' the object the script is on. It then displays the message once until its activated again.

scn test1short myB begin gameMode    if myB       messagebox "Boolian works"       set myB to 0   endif endbegin OnActivate	set myB to 1end

User avatar
Louise
 
Posts: 3407
Joined: Wed Nov 01, 2006 1:06 pm

Post » Mon Oct 18, 2010 12:21 pm

If (myB == 7) -------> Check the memory location "myB" if it has a value, compare it with 7, if it equals 7, execute code below, otherwise skip it.

if (myB) --------------> Check the memory location "myB" if it has a value, execute code below.


They both check the variable to see if there is anything stored. The first statement will compare the obtained value (if any) with 7, in order to proceed. The second statement will proceed if any value is found.


I just find booleans more convenient for certain tasks, and for the record they are smaller than integers. Not that it matters much in oblivion.
User avatar
Emily Jones
 
Posts: 3425
Joined: Mon Jul 17, 2006 3:33 pm

Post » Mon Oct 18, 2010 6:38 am

I just find booleans more convenient for certain tasks, and for the record they are smaller than integers. Not that it matters much in oblivion.


Yep - a Boolean only takes 1 bit of storage space vs. 1 byte (8 bits) for an integer or 2 bytes (16 bits) for a short -- but nowadays most programs aren't designed for compactness since memory is cheap and available !
User avatar
stephanie eastwood
 
Posts: 3526
Joined: Thu Jun 08, 2006 1:25 pm


Return to IV - Oblivion