サイトアイコン schilverberch★ROBLOX

S-8 ストーリーのコーディング

プレイヤーがすべての質問に答えると、その答えとストーリーが組み合わされたものが表示されます。ストーリーも文字列で変数に格納され、プレイヤーの答えを格納した文字列と結合されます。

最初の文字列のコーディング

ストーリーのために書いた最初の文を覚えていますか?  それをコードに追加する時が来ました。

  1. テストプレイが停止していることを確認してください。
  2. ゲームエディタの上にある StoryManager スクリプト タブをクリックして、スクリプトに戻ります。スクリプトが表示されない場合は、エクスプローラを見て、StoryManager を見つけてダブルクリックします。
  3. 質問を入力した場所の下に、 storyという名前の新しい変数を作成します。変数名が小文字であることを確認してください。
    -- Code story between the dashes
    -- =============================================
    local name1 = storyMaker:GetInput("What is your favorite name?")

    local story
    -- =============================================
end
  1. 最初の文字列を見つけるには、元のストーリーに戻ります。最初のプレースホルダーの前のすべてを丸で囲むか強調表示します。変数が文の途中にある場合は、残りを後で追加できます。
    元のプレースホルダー:In a tree on a hill, lives the great wizard name1.
  2. 変数 story に以下のような文字列を格納します。最後の単語の後、引用符の前に必ずスペースを入れてください。
  -- 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. 変数 story と同じ行に、「..」と入力します。
    -- 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. 引き続き同じ行に、プレーヤーの回答が入っている変数の名前を入力します。
    -- 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
    -- =============================================

ストーリーを見せる

ストーリーが入力されたので、プレイヤーに表示する必要があります。

  1. 2番目の破線の下に、storyMaker:Write() を見つけてください。() の間に、変数 story を入力します。これは、ゲームにストーリーを書き込むようにプログラムへ指示します。
  -- 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)
  1. ゲームをプレイテストします。2つの文字列 (下の図では異なる色で表示) が結合されているのがわかります。

トラブルシューティング

文が表示されない場合は、次のいずれかを試してください。

質問されていない場合
ストーリーが組み合わさっていれば
ストーリーが表示されない場合
モバイルバージョンを終了