
你幾乎已經完成了項目!
剩下的就是完成第一句話,然後添加另一個問題,讓玩家有更多選擇。
完成句子
要將更多的字或句點添加到句子中,使用連接字串加入另一個字串。
在故事變量的同一行上,輸入 ..
添加包含句子剩下部分或只是句點的另一個字串。不要忘記在句尾加一個額外的空格。
-- 衝擊之間的代碼故事-- =============================================local name1 = storyMaker:GetInput("What is your favorite name?")local story = "In a tree on a hill lives the great wizard " .. name1 .. ". "-- =============================================
添加第二個問題
要提出第二個問題,請創建一個新問題,並持續添加到同一變量中,包含故事。
決定要從故事的第二句中刪除哪個單詞。
原始暫時佔位:: *每天早上,巫師喜歡吃一大碗蜂蜜烤熟的食物。 *food1 。
在第一個變量之下,創建一個新變量來作為暫時器。
local name1 = storyMaker:GetInput("What is your favorite name?")local food1local story = "In a tree on a hill lives the great wizard " .. name1 .. ". "使用 storyMaker:GetInput("") 向玩家提問並儲存答案。
local name1 = storyMaker:GetInput("What is your favorite name?")local food1local story = "In a tree on a hill lives the great wizard " .. name1 .. ". "在故事變量中,使用 .. 將下一個故事字串連接在一起,確保包含句子結尾後的空格。
local name1 = storyMaker:GetInput("What is your favorite name?")local food1 = storyMaker:GetInput("What is your favorite food?")local story = "In a tree on a hill lives the great wizard " .. name1 .. ". " .. "Every morning, the wizard loves eating a giant bowl of honey roasted "在新故事字串之後,連接第二個問題的答案,並以點號結束。
local name1 = storyMaker:GetInput("What is your favorite name?")local food1 = storyMaker:GetInput("What is your favorite food?")local story = "In a tree on a hill lives the great wizard " .. name1 .. ". " .. "Every morning, the wizard loves eating a giant bowl of honey roasted " .. food1 .. ". "
可選添加物
如果您想進一步發展故事,我們包含了一些想法。例如,如何改進故事包括:
- 為故事新增更多行
- 每次新增一組變量和字串時,進行遊戲測試
- 向一位同僚或朋友查詢他們想要自訂的其他字詞。
此外,以下是一些 提示和技巧 ,用於為玩家製作有趣的故事。
使用變數超過一次
變數可以多次使用—只需在你想要包含字詞的地方使用字串連接即可。 範例代碼 : "I am " .. name1 .. " and you are in the palace of " .. name1 .. "!" 結果 : 我是 Sameth,你在 Sameth 的宮殿裡!
添加行間分隔符
行間斷點可以通過輸入 \n 在字串中添加。此外,多於一個行間斷點可以像 \n\n 一樣結合。 範例代碼 : "One \n Two \n\n Three" 結果 :
一
二
三