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

5 min

Store Info Inside the Variable

What’s stored inside of variables can be changed by using the = symbol. A variable might change many times inside of a script or as the program runs.

  1. After the variable name, like local name1, type =
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
    local name1 =
The next step will be to ask the players a question and store their answer inside of the variable.

  1. After =, type storyMaker:GetInput("Question"). The code must be typed exactly as is, and capital letters must match.
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
	local name1 = storyMaker:GetInput("Question")
storyMaker:GetInput()

Scripts can talk to each other. This game has a second script named StoryMaker, and inside of that is code for getting player input. The variable just made will run the code from the StoryMaker script and then store the player’s answer.


String Types

Variables can store different types of data including small numbers, true or false values, and strings. String type variables are special because they can store whole sentences.

It’s easy to spot string type variables because they’re always in quotation marks "like this".

  • Replace "Question" with what you want to ask players in order to complete the next line of the story. Don’t forget to include the quotation marks ("").
while playing do
    storyMaker:Reset()
 
    -- Code story between the dashes	
    -- =============================================
 
    local name1 = storyMaker:GetInput("What is your favorite name?")

Previous Asking Questions Next Testing Your Code