Jump to content

-1#.IND not <0?


botanic
 Share

Recommended Posts

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
Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...