Stencyl has reached 90 memory
Step 71: Just like with the comparison for our condition, the first value is rather easy. Let's drag a couple out and put them where they belong. To do so, we need two of the Set X to for Self blocks one for each condition. Given that our goal is to keep the Ship on the screen, we want to reset the position of our Ship Actor so that it is back on-screen anytime these conditions are met. Since we now have those conditions set up, we can have something happen when they are true. Step 70: The goal of setting up these two conditions is to identify when the Ship has gone too far and has reached the edge of the screen. Here's a image of what we should have so far. Be sure to grab the Minus block to move them in, or we might only get one of the blocks inside of it instead. We need to drag this set of blocks into the other half of our second condition. The result will be a stack of blocks that looks like the below image. We then need to drag the Screen Width into the left side of the Minus block, and the Width of Self into the right side. Width of Self (found in Actor > Properties > Size).Screen Width (found in Scene > View > Screen Bounds).Minus (found in Numbers & Text > Math > Arithmetic).Let's get the following blocks and drop them side-by-side in the workspace. As previously noted, we have to account for the width of the actor on the right side. The second, Greater Than, comparison will be slightly more complex, however. All we have to do is type a 0 into the right half of the Less Than block.
![stencyl has reached 90 memory stencyl has reached 90 memory](https://n1.sdlcdn.com/imgs/b/z/i/Sony-32-GB-Class-10-SDL950084241-1-7caad.jpg)
For our first comparison, we are just going to compare to 0 since an X value of zero is the left side of the screen. Step 69: Now that we have our first value to compare, we need a second value to compare it against. We can click on each one and change them easily with the drop-down menus that appear. We need one more change for these two blocks, we want them to say "x (on screen)" instead of just "x". We want to drag two of these blocks out one for each of our comparison blocks (the blocks). We need a block that tells us that, and we can find it under the Actor category, Position sub-category, Position section visible as x of Self. Step 68: As mentioned previously, one of the numbers we want to compare is the Ship's position. Put the Less Than (shaped like ) in the second, Otherwise If block's empty space. You can find them in the Flow category, Conditions sub-category, in the Equality section. Let's grab the Greater Than and the Less Than blocks from palette. Step 67: For our conditions, we need to compare two numbers the Ship's position and the left or right edge of the screen.
![stencyl has reached 90 memory stencyl has reached 90 memory](https://cdn.eteknix.com/wp-content/uploads/2011/11/75b.jpg)
Stencyl measures an Actor’s x position from the left-most edge of the graphic if we didn't account for the Ship's width, the right side of the ship could go further than the right side of the screen. Note that it will need to take into account the Ship’s width.
![stencyl has reached 90 memory stencyl has reached 90 memory](https://www.eetasia.com/wp-content/uploads/sites/2/2020/05/memory.jpg)
The second will check if it’s past the right-most edge (a value equal to the screen’s width) of the screen. We will use the first to check if the Ship’s position on screen is beyond the left-most edge of the screen (an X position of 0). We need to add an If and an Otherwise If block inside. Step 66: Create a new When Updating Event for the Ship. Let's fix that, we need to restrict the Ship’s position so it can’t go past the screen’s edge. You probably played around with the game so far and noticed something the ship can go off the screen (and doesn't come back!). Comments Crash Course 2: Invaders - Part 9