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

Adding to the Story

5 min

Adding to the Story

Combine the Story and Answer

Next, the first string of the story needs to be combined with the player’s answer. Combining things together is called concatenation. To combine the two strings together, use ..

  1. On the same line as the story variable, type ..
while playing do
    storyMaker:Reset()
      
    -- Code story between the dashes	
    -- =============================================
      
    local name1 = storyMaker:GetInput("What is your favorite name?")
      
    local story = "In a tree on a hill lives the great wizard " ..
  1. Still on the same line, type the name of the variable holding the player’s answer.
while playing do
    storyMaker:Reset()
      
    -- Code story between the dashes	
    -- =============================================
      
    local name1 = storyMaker:GetInput("What is your favorite name?")
      
    local story = "In a tree on a hill lives the great wizard " .. name1

Write the Story and Playtest

Now that the story is typed, it needs to be shown to players.

  1. Under the second dashed line, find storyMaker:Write(). Between the (), type the variable story. This tells the program to write the story in the game.
while playing do
    storyMaker:Reset()
      
    -- Code story between the dashes	
    -- =============================================
      
    local name1 = storyMaker:GetInput("What is your favorite name?")
      
    local story = "In a tree on a hill lives the great wizard " .. name1
     	
    -- =============================================
     		
    -- Add the story variable between the parenthesis below 
    storyMaker:Write(story)
Check Your Work

Make sure that you’ve typed story in the line storyMaker:Write(story) and the capitalization is exactly like the code box. Without this step, the story won’t appear when you play-test.


  1. Playtest the game. You should see the two strings combined together.

If the question is not being asked, check that:

  • The question is inside of quotation marks.

If the story is not combining together, check that:

  • The first part of the story is inside of quotation marks.
  • The name of the variable holding the player answers matches exactly. Capitalization counts!
  • The name of the variable holding the player’s answer is not inside of quotation marks.
  • The two strings are separated by ..

If you can’t see your story appear:

  • Make sure that that you’ve typed the story variable between the () in storyMaker:Write()

Finish Your Sentence

To add more words or punctuation to the sentence, add another string.

  1. On the same line as the story variable, add another ..
  2. Add another string containing the rest of the sentence, or just punctuation. Don’t forget to add an extra space at the end of the sentence.
-- =============================================
 
local name1 = storyMaker:GetInput("What is your favorite name?")
 
local story = "In a tree on a hill lives the great wizard " .. name1 .. ". "

Previous Write the Story Next Add a Second Question