Introduction
Play first!
Slide setup – preparations
Variables
- v_dice: starts with an empty value, will get a random number between 1 and 6 (using JavaScript, see Playing with Numbers)
- v_counter: starts with a value=0 and will be used in the condition for the While loop to fix the number of repetitions to match the random number in v_dice
- v_stair: is a second counter, that will be used to keep track of the total number of steps done. It is needed to know when top is reached. The staircase has 16 steps. It also starts with a value=0.
- v_null: empty variable (see…) used to reset the v_dice variable after each use of the Play button
- v_roll: starts with a value=0, will track the number of dice rolls needed to complete the steps; that number appears after the top of the stairs is reached. It is a third counter.
- v_anim is used to store a random delay used for the On Enter animation.
Events and actions
- Success event of the Play button, it will trigger an advanced action PlayAct
- Success event of the Click box (Reset) it will trigger the advanced action ResetAct
- On Enter event of the Game slide, which triggers the animations: EnterGame
ResetAct triggered by Click Box
PlayAct triggered by Play Button
Decision 1 ‘Random’ (standard action)
window.cpAPIInterface.setVariableValue("v_dice",Math.floor(Math.random()*(7-1))+1);
Decision 2 ‘EndCheck’ (conditional IF action)
This decision checks if the character has reached the top by comparing the user variable v_stair with the total number of steps (16). Contrary to v_counter, v_stair is only reset to 0 when re-entering the Game slide (using ResetAct).
The Play button is hidden (to avoid disturbing the rest of the sequence) and the static multistate dice.
The original character disappears, is replaced by a group (character + click box + text balloon) with some default effects.
If the condition is not fulfilled (ELSE), which means the top has not yet been reached, the variable v_roll is incremented by 1.
Decision 3 ‘ShowNumber’ (While loop)
- The number of steps taken by the image cannot go beyond the random number stored in v_dice (see first decision) and
- The total number of steps done, stored in v_stair, cannot be greater than 16, number of steps in this staircase.
The commands to be done while that AND combination results in True are:
- Switching the static dice to the next state (see image of the Object states for this static dice above)
- Character gets on the next step (using custom effect StepUp, but that name has been changed by Captivate to the name of the effect it was based on ‘RightToLeft’.
- The variable v_counter is incremented, it is this variable which is used in the first condition
- The variable v_stair is incremented; that variable is not reset by clicking on the Play button, is necessary to check if the top is reached (decision 2 ‘EndCheck’).
EnterGame triggered by the On Enter event
Here is the Preview, let me know if you need more details
Questions?
Fire away. Creating this game was a lot of fun, ‘while‘ exploring ‘while‘ loops. Let your creative juices surge!
You must be logged in to post a comment.