Jump to content

Recommended Posts

Posted (edited)

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
Posted (edited)

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

Posted

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

Posted

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

Posted

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
Posted

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

Posted

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

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
×
×
  • Create New...