You didn’t state if the three variables being declare were Story or Temporary scoped, so I will assume they are temporary and that an (set:)
macro call like the following is being done earlier in the Passage that contains the link.
(set: _chanceToGoRoom1 to 56, _chanceToGoRoom2 to 4, _chanceToGoRoom3 to 40)
The (random:)
macro can be used to inclusively generate a random integer within a range. In this specific case that range would be between 1 and the sum of all the related ‘chance’ variables.
(set: _roll to (random: 1, _chanceToGoRoom1 + _chanceToGoRoom2 + _chanceToGoRoom3))
The (cond:)
macro can be used to determine which Passage to transition to based on the value of the roll.
(set: _passage to (cond: _roll <= _chanceToGoRoom1, 'Room1', _roll <= (_chanceToGoRoom1 + _chanceToGoRoom2), 'Room2', 'Room3'))
note: The logic of above works like so:
- the range of roll is between 1 and 100.
- a roll between 1 and 56 (inclusive) results in the ‘Room1’ Passage being selected.
- a roll between 57 and 60 (inclusive) results in the ‘Room2’ Passage being selected.
- a roll between 61 and 100 (inclusive) results in the ‘Room3’ Passage being selected.
At this point there are basically two potential techniques that can be used to combine the above together to cause a Passage Transition:
1: Pre-determine the Passage before showing the link.
This allows a (link-goto:)
macro to be uses to create the link, but it does allow a knowledgeable end-user to determine and potentially change which Passage they will be sent to before selecting the link.
(set: _roll to (random: 1, _chanceToGoRoom1 + _chanceToGoRoom2 + _chanceToGoRoom3))
(set: _passage to (cond: _roll <= _chanceToGoRoom1, 'Room1', _roll <= (_chanceToGoRoom1 + _chanceToGoRoom2), 'Room2', 'Room3'))
(link-goto: 'next room', _passage)
2: Determine the Passage after the end-user selects the link.
In this case a (link:)
plus (go-to:)
macro combination will be used to cause the transition, and because the choice of target Passage is done within the link’s Hook the end-user can’t determine or alter which Passage.
(link: 'next room')[
(set: _roll to (random: 1, _chanceToGoRoom1 + _chanceToGoRoom2 + _chanceToGoRoom3))
(set: _passage to (cond: _roll <= _chanceToGoRoom1, 'Room1', _roll <= (_chanceToGoRoom1 + _chanceToGoRoom2), 'Room2', 'Room3'))
(go-to: _passage)
]