Howdy, Stranger!

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

[harlowe] How can I round a random number without it showing when I test the passage?

Let's say I generate a number as part of an equation that makes it very likely that it will have a decimal. How can I round it down (that is, disregarding the decimal part) without it being printed automatically?

Comments

  • edited April 2017
    You can use (ceil:), (floor:), and (round:). For example:
    (set: $stat to 2.6)
    (set: $var to 1.1)
    
    <!-- (ceil:) always rounds up -->
    (print: (ceil: $stat)) <!-- yields 3 -->
    (print: (ceil: $var)) <!-- yields 2 -->
    
    <!-- (floor:) always rounds down (truncates) -->
    (print: (floor: $stat)) <!-- yields 2 -->
    (print: (floor: $var)) <!-- yields 1 -->
    
    <!-- (round:) rounds to nearest -->
    (print: (round: $stat)) <!-- yields 3 -->
    (print: (round: $var)) <!-- yields 1 -->
    

    What exactly do you mean about it printing automatically?
  • or the same macros as suggested by @Chapel except assigned to a temporary variable.
    (set: $stat to 2.6)
    (set: $var to 1.1)
    
    <!-- (ceil:) always rounds up -->
    (set: _result to (ceil: $stat)) <!-- assigns 3 -->
    (set: _result to (ceil: $var)) <!-- assigns 2 -->
    
    <!-- (floor:) always rounds down (truncates) -->
    (set: _result to (floor: $stat)) <!-- assigns 2 -->
    (set: _result to (floor: $var)) <!-- assigns 1 -->
    
    <!-- (round:) rounds to nearest -->
    (set: _result to (round: $stat)) <!-- assigns 3 -->
    (set: _result to (round: $var)) <!-- assigns 1 -->
    
  • Chapel wrote: »
    What exactly do you mean about it printing automatically?

    I meant that when I used the (round:) macro, it showed the resulting number when the passage was tested, when I wanted it to remain hidden.
  • edited April 2017
    Rafe wrote: »
    ...it showed the resulting number when the passage was tested...
    The Test option tells the story format to run the story in Debug Mode, depending on which story format (brand and version) you have selected the resulting page will/can display debug information like: 1 which macros were used; and 2 the current state of the referenced story variables.

    You should be using the Play option if you want to see the story the same way that a reader will.
Sign In or Register to comment.