PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

String Variables

String Variables

Whenever you create a new script, at the top of the script editor is the print function print("Hello world!") It’s famous for being one of the first lines of code people learn how to write.

Print functions output text to the screen. Any time your phone sends you a notification, you’re seeing a print function in action!

Variable Types - Strings

"Hello World" is a string variable type. Variables are containers for information the program can use and change, like player names or points.

There are lots of types of variables. String variables hold a mix of letters and numbers. They’re good for things like names or addresses, but not good for counting. String type variables always sit inside of quotation marks, “like this”.

Examples of strings:

  • I am 100 years old"
  • 42
  • wo0t!

Code Your Own Message

Instead of saying Hello World, create your own message by changing the string in the print function.

  1. In the Script Editor, replace "Hello World" with "Blank are my favorite animals!".
print ("Porcupines are my favorite animal!")

Testing Output

To test your code, you’ll need to use the Output Window.

To open or close the Output window:

  1. Select the View menu tab.
  2. Click Output.

Test Your Script

The Output window displays print functions and helpful error messages for game developers whenever the game is run.

  1. Click Play to test your script. Your new string will show up in the Output window.

Returning to the Script

Now that you know how to test your script, let’s go back into the script editor.

  1. Stop the playtest.
  2. Go back to the script by clicking on the script editor.
Script Tab Missing?

If you don't see the script editor, double-click the name of the script in Explorer to reopen the script.

Troubleshooting Your Code

No matter how long you’ve been coding, sometimes you’ll find errors that keep your program from running. Troubleshooting is the process of looking through your code to find and fix problems.

If your code didn’t work:

  • Make sure print is lowercase.
  • The string is surrounded by quotation marks: "like this".
  • The string is inside the parentheses: ("like this").
  • Ask a friend for help or try re-doing your work from the start.

Create an Error

To better understand what errors look like, let’s purposely create an error.

  1. Open the script.
  2. Delete a quotation mark from the print statement.
  3. Hover over the red line to see an error message. In this case, you should see Unfinished string meaning the string is missing a quotation mark.

Read an Error

Error messages show up as red lines in both the Script Editor and Output Window. You can use these error messages to help pinpoint the problem.

  1. Press Play to run your code.
  2. Click on the red message in the Output window; this will take you to where the error is found in your code.