Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Having issues with If, Elseif

I'm having trouble nesting elseif statements together

(set: $variable to (random:1,6))
$variable
(if: $variable < 3) [Variable is 1 or 2]
(elseif: $variable is 3 or 4 or 5) [Variable is 3-5]
(elseif: $variable is 6) [Variable is 6]
I'm using above as a test to see if the code is behaving as I want. I want it to display message 1 if $variable is 1 or 2, message 2 if variable is anywhere from 3 to 5, and message 3 otherwise. INSTEAD what happens is this:

If $variable is anywhere from 1 to 5, it works properly. If $variable is 6, it displays the second message [Variable is 3-5] instead of the third [Variable is 6]

When I change all 3 statements to if statements, then whenever I roll a 6, BOTH message 2 and message 3 pop up, so I'm thinking my 3 or 4 or 5 isn't a good way to do it

I would appreciate any help or suggestions.

Thanks

Comments

  • You cannot run multiple conditionals off of one identifier like you are attempting.  What you should be doing is:

    (elseif: $variable is 3 or $variable is 4 or $variable is 5)[Variable is 3-5]
    Which you can write more concisely using the it keyword to continue to referencing the same variable:

    (elseif: $variable is 3 or it is 4 or it is 5)[Variable is 3-5]
    Since your variable is a number, you could also write that with different operators as:

    (elseif: $variable >= 3 and it <= 5)[Variable is 3-5]
  • Wonderful. That makes a lot of sense. Thank you so much
Sign In or Register to comment.