How to create your own start screen with cursor

I'm going to teach people how to make a moving cursor that can be used for a main menu
Difficulty: beginner

First, you will want to go to your player code and add this:

on enter do
    cursor = 0
end

on draw do
    label "{cursor}" at 0,0
end

The enter do event tells the playercode to change the cursor variable to be 0

On draw do tells the game to label the cursor value at 0,0 (the top left corner of the screen)

Now we are going to create three sprite tiles

Two will be your arrow tiles and one will be the cursor. Name your first tile to be cursor_up and the 2nd one to be cursor down. The cursor can be called cursor

Next you are going to want to create a world tile that is blank and solid.
Place your tiles somewhere on the map, but for this tutorial, we will be putting cursor_up at tile position 20,7 and cursor_down at 20,9. Place the player in the middle and put two solid world tiles between the player.


This will make it where the player can only interact with only cursor_up and cursor_down

Now for the code

cursor_down:

on interact do
    if cursor<=0 then
        cursor = 0
    else
        cursor--
    end
end

When the player interacts with the tile (on interact do) if the value of the cursor variable is less than or equals to 0 then it will equal 0 or else the value of the cursor variable will be minus 1 or --

If the value of the cursor variable is 2 or more then the value of that variable will minus 1 every time you interact with that tile

cursor_up:

on interact do
    if cursor>=3 then
        cursor = 3
    else
        cursor++
    end
end

Its similar to the cursor_down code, but if you interact with the tile, if the value of the cursor variable is greater than or equals 3 then the cursor variable will equals 3. You can change this to any number if you want your main menu to have more or less options

When you run the game, when you interact with the tiles, this should happen:

firefox_LnKBNmcX0P

Now we are going to move the cursor
Actually, we are going to change the player code to be only this:

on draw do
    label "{cursor}" at 0,0
end

For the room code, we are going to change it to this:

on enter do
    cursor = 3
end

We are going to want to call the cursor tile cursor_icon
We are also going to place that cursor icon at 8,6 on the map
Now to to the updated code for cursor_up and cursor_down

on interact do
    if cursor>=3 then
        cursor = 3
    else
        cursor++
    end
    if cursor==3 then
        tell 8,6 to
            swap "cursor_icon"
            tell 8,7 to
                swap "white"
                tell 8,8 to
                    swap "white"
                end
            end
        end
    else
        if cursor==2 then
            tell 8,6 to
                swap "white"
                tell 8,7 to
                    swap "cursor_icon"
                    tell 8,8 to
                        swap "white"
                    end
                end
            end
        else
            if cursor==1 then
                tell 8,6 to
                    swap "white"
                    tell 8,7 to
                        swap "white"
                        tell 8,8 to
                            swap "cursor_icon"
                        end
                    end
                end
            end
        end
    end
end

This might look like giberish to you, but I'll explain what it all means.
Before, we had cursor_up only change the value of the variable of cursor from 0 to 3.
Under the first end statement there is an if statement that says:

If the cursor variable = 3 (==) tell the tile position 8,6 to swap that tile as "cursor_icon" (our cursor), then it tells the tile position 8,7, and 8,8 to swap as "white" (default blank tile)
else if the cursor variable = 2 then it tells the tile position 8,6 to swap as "white", the tile position 8,7 to to swap as the cursor tile and 8,8 as "white.
Again, else if the cursor variable = 1 then tell 8,6 to swap as "white", 8,7 to swap as "white", and 8,8 to swap as "white" (edited)
Now for cursor_down:
Its the same as before, but with the same exact code new code added to cursor_up:

on interact do
    if cursor<=1 then
        cursor = 1
    else
        cursor--
    end
    if cursor==3 then
        tell 8,6 to
            swap "cursor_icon"
            tell 8,7 to
                swap "white"
                tell 8,8 to
                    swap "white"
                end
            end
        end
    else
        if cursor==2 then
            tell 8,6 to
                swap "white"
                tell 8,7 to
                    swap "cursor_icon"
                    tell 8,8 to
                        swap "white"
                    end
                end
            end
        else
            if cursor==1 then
                tell 8,6 to
                    swap "white"
                    tell 8,7 to
                        swap "white"
                        tell 8,8 to
                            swap "cursor_icon"
                        end
                    end
                end
            end
        end
    end
end

The only difference is that we have to change the top portion of the code to be if cursor is less than or equals to 1 then it will equals 1.
When you run the code, this is what should happen:
firefox_RptwxZ9fJR

The reason for the tile swap is for letting the cursor_icon to move around.
Now we will add Text onto the screen

Now back to the player code:

on draw do
    label "{cursor}" at 0,0
    if cursor>=1 then
        label "play game" at 9,6
        label "options" at 9,7
        label "exit" at 9,8
        else
    end
end

Back to on draw. If the cursor >=1 then it will label "play game" at 9,6 and label "options" at 9,7, and label "exit" at tile position 9,8

While we are at it, we can also change the player sprite to be blank and do the same for cursor_up and cursor_down

When you run the code, this should happen:
firefox_sZVk0Jfu8A

We can go to the player code and comment out label "{cursor}" at 0,0 with //label "{cursor}" at 0,0

Now we are going to want to edit the player code and add a new event called on confirm do

    // label "{cursor}" at 0,0
    if cursor>=1 then
        label "play game" at 9,6
        label "options" at 9,7
        label "exit" at 9,8
    else
    end
end

on confirm do
    if cursor==3 then
        tell "player" to
            goto 12,9 in "start"
        end
    end
end

Confirm is the A button. If the cursor variable = 3 then tell the player to goto tile position 12,9 in the room "start". If you started with the default example game, there should be a room with floppies, a computer, and a exit.
Next we will want to go to the start room and create room code:

on enter do
cursor = 0

When you enter the start room, the variable cursor will = 0 and the start screen and cursor will not be displayed on the screen.

There is an issue though, our player is still invisible. There is a way to make the player show up correctly.

firefox_0zvQfhtBUl

We are going to create a new player tile. It can be whatever you want it to be.
we are going to call the new player tile player_room
For the room code, we are going to add one more variable.

start room:

on enter do
    cursor = 0
    level_start = 1
end

menu room:

on enter do
    cursor = 0
    level_start = 0
end

Actually, one more thing, we will also want to add something to both room codes. Under the variable level_start, we are going to add this:

tell "player" to
      call "playertype"
end

This will tell the player code to call a event, but that currently doesn't exist, so we are going to create that now. In the player code, we are going to create a new event.

on playertype do
    if level_start==1 then
        swap "player_room"
    else
        swap "player"
    end
end

If the variable level_start = 1 then swap the player tile to the other player tile "player_room" else, if the variable doesn't = 1 then swap to "player"

When you run the code, this is how it should work:

firefox_jR7JF1LMuZ

You can go back into the player code and change the confirm event (press A) to where if cursor = 2 or cursor = 1 then they will do different things. Lets try that out real quick

on confirm do
    if cursor==3 then
        tell "player" to
            goto 12,9 in "start"
        end
    end
    if cursor== 1 then
      fin "You cannot quit the game. There is no escape"
    end
end

firefox_6ybUhmvHu6

If cursor == 1 then the game will end with a message. In reality, you aren't exiting the game, but restarting the game. The only true way to exit the game is by pressing the menu button and selecting home

I hope this tutorial was helpful. If you liked the tutorial or have any criticisms with it, please let me know. Have a good night.

6 Likes