a few lints of Math instead of many elseifs

Post » Tue Aug 19, 2014 4:14 am

I need to do the following, is there a way to do this mathematically with only a few lines of script

and yet still get the EXACT LEVEL floats shown below?

Function CheckLevel()
If StaminaPerc <= 0.1
Level = 0.1
elseIf StaminaPerc <= 0.15
Level = 0.15
elseIf StaminaPerc <= 0.2
Level = 0.2
elseIf StaminaPerc <= 0.25
Level = 0.25
elseIf StaminaPerc <= 0.3
Level = 0.3
elseIf StaminaPerc <= 0.35
Level = 0.35
elseIf StaminaPerc <= 0.4
Level = 0.4
elseIf StaminaPerc <= 0.45
Level = 0.45
elseIf StaminaPerc <= 0.5
Level = 0.5
elseIf StaminaPerc <= 0.55
Level = 0.55
elseIf StaminaPerc <= 0.6
Level = 0.6
elseIf StaminaPerc <= 0.65
Level = 0.65
elseIf StaminaPerc <= 0.7
Level = 0.7
elseIf StaminaPerc <= 0.75
Level = 0.75
elseIf StaminaPerc <= 0.8
Level = 0.8
elseIf StaminaPerc <= 0.85
Level = 0.85
elseIf StaminaPerc <= 0.9
Level = 0.9
elseIf StaminaPerc <= 0.95
Level = 0.95
elseIf StaminaPerc <= 0.99
Level = 0.99
endif
User avatar
Nims
 
Posts: 3352
Joined: Thu Jun 07, 2007 3:29 pm

Post » Tue Aug 19, 2014 3:20 am

Hmmm, well I hope my math is okay (and keep in mind I haven't written much papyrus for a bit)

Int Lev = Math.Floor( ( StaminaPerc + 0.05 ) / 0.05 )

Float Level = 0.05 X Lev

If Level == 1.0

Level = 0.99

EndIf

User avatar
A Boy called Marilyn
 
Posts: 3391
Joined: Sat May 26, 2007 7:17 am

Post » Mon Aug 18, 2014 4:19 pm

I think the following would do it:

Float Step = 0.05Float Mult = Math.Ceiling(StaminaPerc / Step)Float Level = Mult * Step; Add the following if you want to be more similar to your code.If (Level == 1.0)  Level = 0.99EndIf

It's not exactly the same, as your code does not set Level if StaminaPerc is bigger than 0.99.

User avatar
Stryke Force
 
Posts: 3393
Joined: Fri Oct 05, 2007 6:20 am

Post » Mon Aug 18, 2014 6:45 pm

Actually come to think of it you need StaminaPerc + 0.049999 otherwise StaminaPerc 0.099 will return Level = 0.1 while 0.1 will return Level = 0.15

User avatar
rebecca moody
 
Posts: 3430
Joined: Mon Mar 05, 2007 3:01 pm


Return to V - Skyrim