Displaying messages

Lesson 1 –How to get a Timed Message 

The mistake most creators make when starting out is trying to display text using the duration timer.
You would think that this would work:

WHEN [interact]
…WHEN [duration timer] [3] Do [display] [textvar:Hello World]

But when you test this, the text only appears for a split second. You asked it to display for 3 seconds so why is this happening?
Interact is a button press (normally B). Button presses happen for one frame. The DO part of the Kode only works if the WHEN side is true. So it displays the text for one frame only – and ignores the timer instruction. There are 2 methods to counter this.

Method 1 – Switch Page (easiest method)

page 1
WHEN [interact] Do [switch to page][2]

page 2
DO [display][screen center][textvar:Hello world]
WHEN [countdown timer][3] Do [switch to page][1]

This will display some text in the center of the screen for 3 seconds every time the player interacts with the object. This is very useful for displaying text on locked doors and boxes.

e.g.
page 1
WHEN [interact]
…WHEN [key][held in inventory] DO [power on]
…/…WHEN[Else] DO [switch to page][2]

page 2
DO [display][screen center][textvar: Sorry this door is locked]
WHEN [countdown timer][3] Do [switch to page][1]

Page 2 can contain any other command you like. It can play a piece of music, create an effect, change a variable. Just set the countdown timer so that it returns to the interact command after you have run all the lines of Kode for the page.

If you want your message to display until the player presses a button change the countdown timer line to
WHEN [A] [pressed] DO [switch page] [1]

Method 2 – Boolean

A Boolean is a statement that can be true or false.
WHEN [Once] DO [booleanvar:showtext][=][false]
WHEN [interact] DO [booleanvar:showtext][=][true]
WHEN [booleanvar:showtext][=][true]
…WHEN [duration timer][3] DO [display][screen center][textvar:Hello world]
…WHEN [countdown timer][3] DO [booleanvar:showtext][=][false]

This will display the text for 3 seconds, then reset the boolean back to false waiting for another interaction.

For a locked door situation:

WHEN [Once] DO [booleanvar:showtext][=][false]
WHEN [interact]
…WHEN [key][held in inventory] DO [power on]
…/…WHEN [else] DO [booleanvar:showtext][=][true]
WHEN [booleanvar:showtext][=][true]
…WHEN [duration timer][3] DO [display][screen center][textvar:You need a key]
…WHEN [countdown timer][3] DO [booleanvar:showtext][=][false]

Lesson 2 – Displaying multiple timed messages

Lets say you want to create a title sequence with credits. You have 5 lines of text, and you want them to appear one at a time

WHEN DO [display][screen top center][textvar: Name of my game]
WHEN[countdown timer][3] DO [display][screen top center][textvar: Subtitle]
WHEN[countdown timer][6] DO [display][screen top center][textvar: Line 1 of your credits]
WHEN[countdown timer][9] DO [display][screen top center][textvar: Line 2 of your credits]

This will display each line one at a time underneath each other every 3 seconds

If you want the credits to appear one at a time on their own

WHEN [duration timer] [3] DO [display][screen center][textvar: Name of my game]
WHEN[countdown timer][3]
…WHEN [duration timer] [3] DO [display][screen center][textvar: Subtitle]
WHEN[countdown timer][6]
…WHEN [duration timer] [3] DO [display][screen center][textvar: Line 1 of your credits]
WHEN[countdown timer][9]
…WHEN [duration timer] [3] DO [display][screen top center][textvar: Line 2 of your credits]

You may want to add one second to the countdown timers so they appear to fade and are replaced

Lesson 3 – Displaying random messages

To get some variety into your game you may wish to have random messages for the same action. To do this use a random number variable.
Lets use the door opener as an example:

page 1
WHEN [interact]
…WHEN [key][held in inventory] DO [power on]
…/…WHEN[Else] DO [switch to page][2]

page 2
DO [numvar:textchoice][=][random number][as integer][1][to][4]
WHEN [textchoice] [=] [1] DO [display][screen center][textvar: Sorry this door is locked]
WHEN [textchoice] [=] [2]DO [display][screen center][textvar: You will need a key]
WHEN [textchoice] [=] [3]DO [display][screen center][textvar: The door handle won’t budge]
WHEN [textchoice] [=] [4]DO [display][screen center][textvar: Access denied]
WHEN [countdown timer][3] Do [switch to page][1]

Lesson 4 – Displaying multiple lines of text on separate lines and in a box

If your line of text is longer than the width of the screen you will not see the ends of the text. The text box will not split your text variable into separate lines to fit the screen. You will need to do this yourself. So make sure you dont put too much text in yout text variable.

WHEN DO [display][screen center][textvar:Hello World][+][newline][+][textvar:This is my second line]

You can add as many + newline + as you like. Newline can be found as a grey tile within your text variables.

If you use Say instead of Display the text will appear in a black box with a blue fancy border and a tail (like a speech bubble)

If you use Display then after that use modify and text box gallery you will find various different styles of Text box. Some with and some without “tails”.

WHEN DO [display][Fantasy message][screen center][textvar:Hello World][+][newline][+][textvar:This is my second line]
is the tailless version of above

WHEN DO [display][Fantasy say][screen center][textvar:Hello World][+][newline][+][textvar:This is my second line]
is exactly the same as
WHEN DO [Say][screen center][textvar:Hello World][+][newline][+][textvar:This is my second line]

Lesson 5 – Multiple lines of text with a button for next

(Disable the player brain so that the A button does not make him jump)

In a logic cube

WHEN [started to] DO [player][brain is active][=[false]

WHEN DO [display][screen top center][textvar: Name of my game]
WHEN[numvar:textline][=][1] DO [display][screen top center][textvar: First line of text]
WHEN[numvar:textline][=][2] DO [display][screen top center][textvar: Line 2 of your text]
WHEN[numvar:textline][=][3] DO [display][screen top center][textvar: Line 3 of your text]
WHEN[numvar:textline][=][4] DO [player][brain is active][=[true]
…WHEN [countdown timer][1] DO [destroy][me]
WHEN DO [display][screen bottom center][icon:A]
WHEN [A][pressed] DO [numvar:textline][incremented by][1]

 

Comments are closed.

Powered by WordPress.com.

Up ↑

%d bloggers like this: