Howdy, Stranger!

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

Modular arithmetic in Harlowe?

Is there a way to perform modular arithmetic in Harlowe? Specifically, I am trying to do an in-game clock system using number of minutes in the day, and I know I can use floor division (with floor and /) to give the hours, but I'm trying to give the minutes.

Comments

  • In Harlowe the modulo operator is %.
    (set: $time to 75)
    (set: $minutes to $time % 60)
    
  • Thanks.

    Why is it not in the docs?
  • XndrK wrote: »
    Why is it not in the docs?
    The first comment within the TwineScript operators section of the Harlowe documentation reads as follows:
    +, -, /, *, %, >, <, >=, <=, is, not: these are the same as Twine 1, except for these differences:
    So although there is not a description for each of the operators, modulo is listed there.
  • The problem with that is it depends on people knowing that % is the standard modulo operator. If they're not familiar with Twine 1 or other programming languages they might not realise that.

    On the other hand the guide I'm working on doesn't include it, so I should definitely add it before casting stones.
  • The problem with that is it depends on people knowing that % is the standard modulo operator.
    While what you say is very true and it is also true that the documentation could be clearer, the fact that the OP knew what modular arithmetic is and that they possibly also know that they are programming leads me to believe that they may also be able to google "modular arithmetic programming" to work out which operator is commonly used in programming languages. lol
  • Note: The % operator is the remainder operator, which is not a true modulo operator. The difference is unimportant when working on positive numbers, but when working with negative numbers, the result is likely not to be what you'd expect from a modulus operator.
  • edited October 2015
    Oh.
Sign In or Register to comment.