Hello World!

Last Modified: 8/9/2022

Most programming starts off with a "Hello World!" example as it's very quick and shows you the basic structure of the code syntax, and this is no different.

This will be a quick tutorial as it really only involves two commands: Locate and Print. If you aren't familiar with these commands, click the links to learn more about them. If you just want/need a quick explanation, then Locate sets the cursor position for the Print command. The Print command displays text on the screen (either from a variable or a literal expression).

Let's display some text to the screen, shall we?

    Print "Hello World!"

Press F5 to compile the above line, and open the ROM in your favorite Sega Genesis/Mega Drive emulator. You can find the ROM in the \work\ folder of the SecondBASIC Studio program folder.

What if we want to change the location of the text? We use the Locate command.

    Locate 10, 5
    Print "Hello World!"

And that's all there is to displaying text on the screen. You can also use variables in place of the quoted text, as well as numerical values:

    Locate 10, 5
 
    a = 15
    text$ = "My favorite number is:"
 
    Print text$; " "; a

The Print command is very useful for quickly displaying information. One thing to keep a mental note of is if you scroll the background plane that the text is written to (default plane is Scroll_A), the text will also scroll.

Lastly, while this command is useful, it might not fit all of your needs when making a game and you may need to write a custom text routine.