Scripting help - comparing negative numbers

Post » Thu Jun 21, 2012 12:57 am

Hi all
First post :-)

I have successfully started my first mods, and things are moving along nicely. However, a recent problem is driving me nuts and has really ruined my day and mood. Have not been able to find the magic thread, section or paragraph explaining what I am doing wrong, so I hope you can help me. Also, I expect the answer to be really embarassingly simple, so that probably explains the mood-thing ;-)

Anyways, to isolate the problem I have created a new Quest, start-enabled, with a single script, and added the following code to the OnInit-event.
Spoiler
Scriptname jtTEST extends QuestEvent OnInit()  Int iNumber = -3  If (iNumber >= 0)	Debug.TraceAndBox("iNumber greater or equal to 0")  ElseIf (iNumber < 0)	Debug.TraceAndBox("iNumber less than 0")  ElseIf (iNumber < -2)	Debug.TraceAndBox("iNumber less than -2")  Else	Debug.TraceAndBox("Whoops: " + iNumber )  EndIfEndEvent

I get the messagebox allright when starting the mod. But instead of "iNumber less than -2" (which I expect) I get "iNumber less than 0".
I have tried casting back and forth between floats and ints, but no luck. Somehow I cannot figure out to do comparisons on negative numbers, and it turns out I really want to ;-). What am I doing wrong?
User avatar
Multi Multi
 
Posts: 3382
Joined: Mon Sep 18, 2006 4:07 pm

Post » Thu Jun 21, 2012 8:55 am

You just need to change the order of your < 0 and < -2 elseifs. Any number that is less than -2 is also less than 0.
User avatar
Kirsty Wood
 
Posts: 3461
Joined: Tue Aug 15, 2006 10:41 am

Post » Thu Jun 21, 2012 2:09 pm

Yup, embarassing. Thank you :blush:
User avatar
dav
 
Posts: 3338
Joined: Mon Jul 30, 2007 3:46 pm

Post » Wed Jun 20, 2012 11:35 pm

That's because it gets to the <0 elseif, which is true whether it is -1 or -2 or -100, and so it pumps out the message. The condition on that elseif should read iNumber <0 && iNumber >= -2
User avatar
Roberta Obrien
 
Posts: 3499
Joined: Tue Oct 23, 2007 1:43 pm

Post » Thu Jun 21, 2012 9:37 am

We've all done such things :)
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm


Return to V - Skyrim