Howdy, Stranger!

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

So I'm doing a basic combat system...

edited February 2014 in Help! with 1.x
I need two things, first and foremost. More shall certainly crop up as I progress. :D

1. Firstly, I need a way to roll a random number in a certain range - for instance, pick a random number between 1 and 100.
Something along the lines of <<set $number random(0,100)>>, but that doesn't work since it's just my garbage code of course. xD

2. Secondly, I need a way to say "if the resulting number is between, say, 1 and 10, show this Passage".

I cannot for the life of me figure out how to do this.

Comments

  • http://www.w3schools.com/jsref/jsref_random.asp
    http://www.w3schools.com/js/js_obj_math.asp

    <<set $number = Math.floor((Math.random()*10)+1)>>

    <<if $number lte 5>>
    <<display "passage">>
    <<else>>
    <<display "Other Passage">>
    <<endif>>
  • To add to Sharpe's excellent comment, I just want to say that if you wanted to explicitly check if a variable is between two numbers, then you should probably use something like this:
    <<if $number gte 1, lte 5>>
    whatever
    <<elseif $number gte 6, lte 10>>
    blah blah
    <<endif>>
    The if statement Sharpe gave would only work if you had something to display for every possible number and if the statements were in a certain order. :)

    Good luck!
  • No, I don't think that's so, Prim, unless I misunderstand you (and that's quite possible since my reading comprehension is rivaled only be plant life).

    Mine shows one passage for numbers between 1-5, and another passage for numbers between 6-10, the possible numbers.

    The first conditional branch states, "If the number is less than or equal to 5." That's 1-5. The second states, "Otherwise . . ." That's 6-10.

    Here's how I personally would handle a conditional branch with more than two entries (though Prim's example certainly works just as well, through it requires several "endif" tags):
    <<if $number lte 3>>
    The number <<print $number>> is less than or equal to 3.
    <<elseif $number gte 4 or $number lte 6>>
    The number <<print $number>> is greater than or equal to 4 or less than or equal to 6.
    <<elseif $number gte 7 or $number lte 9>>
    The number <<print $number>> is greater than or equal to 7 or less than or equal to 9.
    <<else>>
    The number <<print $number>> is 10.
    <<endif>>
    See attached is a story file.
  • So awesome. Thank you very much, guys. Shall experiment with it ASAP! :D
  • It works! Thanks a lot. :)
Sign In or Register to comment.