Odd Cast Variable Behavior

Post » Tue Jun 19, 2012 9:51 am

Edit:
Could you possibly illustrate how to get a float into an integer that can be used in the expression?

I am retrieving
Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)

i want to get those two float values, make them integers and then use them in the expression

original:
i discovered that you cannot place a cast variable inside a double parenthetical expression.
Or is there a way?

compiler chokes on this:

float X = 10
int Y = X as int
int Z = 5
A = ((X - Y) - (X * 5)) - 1
User avatar
Tiffany Holmes
 
Posts: 3351
Joined: Sun Sep 10, 2006 2:28 am

Post » Tue Jun 19, 2012 7:14 am

In your first expression, you're not casting X to an Int...X is sitll a float when the expression comes along. it has nothing to do with the parentheses...there is no auto-castiing in Papyrus.
User avatar
Danny Warner
 
Posts: 3400
Joined: Fri Jun 01, 2007 3:26 am

Post » Mon Jun 18, 2012 8:44 pm

Could you possibly illustrate how to get a float into an integer that can be used in the expression?

I am retrieving
Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)

i want to get those two float values, make them integers and then use them in the expression
User avatar
Kat Ives
 
Posts: 3408
Joined: Tue Aug 28, 2007 2:11 pm

Post » Tue Jun 19, 2012 7:46 am

This is passes the compiler, is this the correct way?

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)  sBegin = afSleepStartTime as int  sEnd = afDesiredSleepEndTime as int  duration = (sEnd - sBegin)endEvent
User avatar
Amy Smith
 
Posts: 3339
Joined: Mon Feb 05, 2007 10:04 pm

Post » Tue Jun 19, 2012 3:48 am

You'd do it like this (W,X,Y, and Z are Float Type)

int NewW = (W as int)Int NewX = (X as int)int NewY = (Y as int)int NewZ = (Z as int)int Result = ((W*X) + (Y*Z))


This is passes the compiler, is this the correct way?

Event OnSleepStart(float afSleepStartTime, float afDesiredSleepEndTime)  sBegin = afSleepStartTime as int  sEnd = afDesiredSleepEndTime as int  duration = (sEnd - sBegin)endEvent

That's the idea...cast all variables as the same type before doing any computations.

No reason you couldn't do the computation as float and then convert like so:

duration = (AFDesiredSleepEndTime - afSleepStartTime) as int

The computation would be more accurate, since it won't round it off until it's done.
User avatar
Angelina Mayo
 
Posts: 3427
Joined: Wed Jan 24, 2007 4:58 am

Post » Mon Jun 18, 2012 9:26 pm

thanks for the clarifications, much appreciated!
User avatar
Roddy
 
Posts: 3564
Joined: Fri Jun 15, 2007 11:50 pm


Return to V - Skyrim