0 votes
by (510 points)
My story has a free-roam element to it and no time limit. At any given time, one of the other characters in the story will be present in specific rooms (each room is a passage) based on the day. What I would like to do is make it so that a certain character, lets call her Sarah, will be in a certain room, lets say the Kitchen, every third day.

I've already set up a time-tracking system which uses the variable $elapsed to keep track of how many days the player has spent in the story. What I need now is to know how I can get an <<if>> macro to check if $elapsed is a multiple of 3 (3, 6, 9, 12 etc.), AND that it will check this no matter how high $elapsed gets.

1 Answer

+1 vote
by (44.7k points)
selected by
Best answer

You can just use one of these two "if" statements:

<<if ($elapsed % 3)>>not multiple of three<<else>>a multiple of three<</if>>
<<if !($elapsed % 3)>>multiple of three<<else>>not a multiple of three<</if>>

This works because the "%" gives the remainder of the value in front of it divided by the value after it.  So the results of "($elapsed % 3)" will only be the numbers "0", "1", or "2".  The number "0" is a "falsy" value, meaning that conditional statements, like an "if", will treat it like it's "false", while all other numbers are "truthy" values.  Also, the "!" means "not", so that will reverse the "falsy" or "truthy" value.

For details see "JavaScript Operators Reference".

by (510 points)
Thanks! This worked like a charm. The wiki doesn't show "%" as one of the operators for if statements so I had no idea there was an operator for this situation.