Jump to content

Recommended Posts

Posted (edited)

What would be the best way to assign an operator to a variable?

What I'm trying to do is assign a '+' or '-' to a variable depending on the output of a random number.

Many thanks in advance.

Edit:Spellcheck...

Edited by Lithium
Posted (edited)

What would be the best way to assign an operator to a variable?

What I'm trying to do is assign a '+' or '-' to a variable depending on the output of a random number.

Many thanks in advance.

Edit:Spellcheck...

Like this?

Local $var

If Random(1, 10) < 5 Then
    $var = "+"
Else
    $var = "-"
EndIf

If $var = "+" Then
    MsgBox(0, "", 1 + 1)
Else
    MsgBox(0, "", 1 - 1)
EndIf

You can't use a variable as an operator, so you'll have to use an If Then to check the variable and then change the operator used.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Posted

I see. I'm trying to cut down on repetition as much as possible in my code but it looks like I'm stuck here.

Thanks for answering my question >_<

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