Variables

Post » Sat Feb 19, 2011 10:18 am

Hey guys,

I was wondering if you can make a script where if a variable is a multiple of say 3 then add item or another code?
User avatar
Ian White
 
Posts: 3476
Joined: Thu Jul 19, 2007 8:08 pm

Post » Sat Feb 19, 2011 2:38 am

you can try and see if this works:

 scn myScriptfloat staticVar		;this is the number youd like to find a multiple offloat multiple		;this is the multiple	float testNumber	short intToFloat Begin ;add your begin block here	set staticVar to 3        set multiple to ????      ;whatever you have in mind		if ( multiple < staticVar )		message "is not a multiple"		return	endif 				set testNumber to (multiple/staticVar)	set inToFloat to testNumber		if ( inToFloat == testNumber )		message "it is a multiple"			;do stuff		else				;do some other stuff	endif	End	


this simply tries to exploit the float to integer conversion striping all the decimals from intToFloat. If testNumber had decimals inToFloat will be smaller and so in theory this should work.....
watch for syntax errors, I haven't used the CS in a while
User avatar
Allison Sizemore
 
Posts: 3492
Joined: Wed Jul 19, 2006 6:09 am

Post » Sat Feb 19, 2011 3:54 am

Here's a simplified version, based on Five Alpha Reductase's script. It uses the same principle, but with a bit less calculation.

scn myScriptfloat staticVar         ;this is the number youd like to find a multiple offloat multiple          ;this is the multiple   short testNumber         Begin ;add your begin block here	set staticVar to 3	set multiple to ????      ;whatever you have in mind	set testNumber to multiple / staticVar	; since testNumber is a short and not a float, it will contain a whole number	if testNumber * staticVar == multiple		message "it is a multiple"      		;do stuff       	else            		;do some other stuff	endif        End    

User avatar
Sxc-Mary
 
Posts: 3536
Joined: Wed Aug 23, 2006 12:53 pm

Post » Fri Feb 18, 2011 11:02 pm

And even simpler again;

scn myScriptlong staticVar        ;this is the number youd like to find a multiple oflong multiple          ;this is the multiple Begin ;add your begin block here	set staticVar to 3	set multiple to ????      ;whatever you have in mind	if multiple % staticVar == 0		message "it is a multiple"      		;do stuff       	else            		;do some other stuff	endif        End

That's what the "mod" AKA "remainder after division" % operator is for. Note this is a strictly integer version... if you want to do this for floats use OBSE's Fmod function, but be warned that comparing floats is fraught with risks, and you'd be surprised how often 0.0 == (some function that should == 0.0) is false.
User avatar
Nathan Maughan
 
Posts: 3405
Joined: Sun Jun 10, 2007 11:24 pm

Post » Fri Feb 18, 2011 9:54 pm

And even simpler again;
...
[/code]
That's what the "mod" AKA "remainder after division" % operator is for.
You're right of course. I for some reason thought that one was part of OBSE's mod libary :confused:
User avatar
Kayla Keizer
 
Posts: 3357
Joined: Tue Dec 12, 2006 4:31 pm


Return to IV - Oblivion