Jump to content
Sign in to follow this  
botanic

-1#.IND not <0?

Recommended Posts

botanic

My code has a chance that the $BlockChance can become invalid, is there any way to test for that, this doesn't work :)

$BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10
        if @error Then $BlockChance = 5
        MsgBox(0, "", $BlockChance)
        if $BlockChance<5 then
            $BlockChance=5
            MsgBox(0, "", $BlockChance)
        EndIf
Edited by botanic

Share this post


Link to post
Share on other sites
Mison

Hi,

$BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10
        if @error Then $BlockChance = 5
        If Not StringIsAlNum($BlockChance) Then $BlockChance = 5 ; check if -1#.IND present

        MsgBox(0, "", $BlockChance)
        if $BlockChance<5 then
            $BlockChance=5
            MsgBox(0, "", $BlockChance)
        EndIf
Edited by Mison

Hi ;)

Share this post


Link to post
Share on other sites
botanic

Doesnt work,

$BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        if @error Then $BlockChance = 5
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        If Not StringIsAlNum($BlockChance) Then $BlockChance = 5 ; check if -1#.IND present
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        if $BlockChance<5 then $BlockChance=5
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        if $BlockChance>94 then $BlockChance=96

If Not StringIsAlNum($BlockChance) Then $BlockChance = 5

is triggered even if it is a number...

Share this post


Link to post
Share on other sites
Beege

StringisALNum checks if its all Alpha Numeric, not all numbers. You want all digits correct?

Share this post


Link to post
Share on other sites
botanic

got it by using int() :)

$BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10
        $BlockChance = int($BlockChance)
        if @error Then $BlockChance = 5
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        if $BlockChance<5 then $BlockChance=5
        MsgBox(0, @ScriptLineNumber, $BlockChance)
        if $BlockChance>94 then $BlockChance=96

Share this post


Link to post
Share on other sites
Beege

StringIsAlNum allows all letters.

$BlockChance=Sqrt(Sqrt($Defender[3][12]+$Defender[3][13]-$Attacker[3][10]))*10
If Not StringIsDigit(StringReplace($BlockChance, '.', '')) Then $BlockChance = 5

Share this post


Link to post
Share on other sites
Mison

Originally I thought to use Int().. but then you will lost all numbers after the decimal point. If that's okay with you, use it.


Hi ;)

Share this post


Link to post
Share on other sites
botanic

just using int() as a way to evaluate for the -1#.IND so it doesn't matter :)

Share this post


Link to post
Share on other sites
jvanegmond

Local $In = -1 ; Input declaration and assignment
Local $BlockChance = 0 ; Output declaration

; Method 1
$BlockChance = Sqrt($In) ; Calculate square root and see if it goes wrong
If @error Then $BlockChance = 5 ; This WILL trigger on -1.#IND!!

; You also know the exact conditions under which it will error..
If ($In < 0) Then ; Trap invalid input
    $BlockChance = 5
Else
    $BlockChance = Sqrt($In)
EndIf

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×