Step 3: Moving the apple across in steps for the numerator
In the next few steps we'll clone the apple a bunch of times to show the numerator, and then show semi-transparent apple clones to represent the denominator. In this step we'll focus on moving the apple across in steps, with the number of steps representing the numerator (as shown in the animation below).
Edit the script on Isaac, and go to the "When player presses key spacebar" event. We'll add two new variables. Make them Property variables, and set them as number variables. Name them "numerator counter" and "denominator counter". These two variables will be used to help us keep track of the amount of apples we need to create.
Set the "numerator counter" to "number numerator", and set "number denominator counter" to "number denominator - number numerator" (the - block is originally + from Operators).
Now we'll position the apple so that its clones will line up nicely with it. Set its x position to 0 and its y position to 150. Use the "x position of myself" block (from Transform) and the "first instance by tag" block (from Sensing) to target the apple by using its tag "apple".
To get the apple to move across in steps, we'll set up messages that Isaac will send to himself. If the apple still hasn't moved far enough to fully represent the numerator, the message will keep being sent to Isaac to keep moving the apple until the fraction has been represented.
Grab the block "send message 'message' to instance other" (from Events) and drag it to the bottom of the previous blocks. Drag "instance other" into the trash and replace it with "myself" (from Sensing). Change the message to "create apples".
Once we've done that, we need a new event to receive this message. Grab "When a message of 'message' is retrieved" (from Events) and drag it into the workspace. Change the message to "create apples".
Inside this message receiver we will check if the numerator counter is bigger than 0, and if it is we will move the apple across by 50 pixels, and decrease the numerator counter by 1. Then we'll send the "create apples" message again, and this message will keep being sent and received until the numerator counter goes down to 0. Each time this message is received, the apple will move across 50 pixels, so it will end up travelling 50 pixels multiplied by the numerator. The goal will be to create clones of the apple each time it moves across, so it will leave a trail of apple clones behind it.
First we need an "if" block (from Control Flow), so grab this block and drag it into the message receiver. Then grab the "=" block (from Operators) and drag it into the "if" block. Change "=" to ">".
Grab "number numerator counter" (from Variables) and drag it into the left side of the ">" block. Then grab a "0" (from Operators) and drag it into the right side of the ">" block.
Now grab the blocks to decrease the numerator counter by 1.
Set the x position of the apple to its current x position + 50. Remember to use the "first instance by tag" block to refer to the apple.
Lastly, grab the "100 milliseconds have passed" block (from Control Flow) and drag it under the "Set x position" block. Then inside the "100 milliseconds have passed" block, place another "send message 'apples' to myself".
Now play the game. The apple will keep moving across a step until the numerator count reaches 0.
In the next steps we will make clones of the apple each time it moves a step so that we can see exactly how many apples are in the numerator.