サイトアイコン schilverberch★ROBLOX

S-5 質問のコーディング

ストーリーの文章を書いた後、単語をプレースホルダーに入れ替えたのを覚えていますか? 今度はプレイヤーに、あなたのゲームに何かを追加する行動を起こします。

スクリプトでは、あなたが作ったプレースホルダーは変数になります。コーディングでは、変数は情報(この場合は単語)のプレースホルダーとなります。

まず、プレイヤーに質問を投げかけます。そして、プレイヤーは答えを入力し、それが変数に格納されます。

変数の作成

変数には、プログラマーに何を格納するかを示す名前がついています。この場合、プレースホルダー用にname1という変数を作成します。

  1. 破線の下をクリックして、「local name1」と入力します。
-- GLOBAL VARIABLES
local storyMaker = require(script:WaitForChild("StoryMaker"))

-- Code controlling the game
local playing = true

while playing do
    storyMaker:Reset()

    -- Code story between the dashes
    -- =============================================
    local name1


    -- =============================================

    -- Add the story variable between the parenthesis below
    storyMaker:Write()

    -- Play again?
    playing = storyMaker:PlayAgain()
end

変数の設定

さて、プレイヤーはプレースホルダーの中に何かを入れる機会を持つ必要があります。変数を変更するには、「=」という記号を使って変数に何かを設定する必要があります。

  1. name1の後に必ずスペースを追加してから、=と入力します。
while playing do
    storyMaker:Reset()

    -- Code story between the dashes
    -- =============================================
    local name1 =

    -- =============================================

    -- Add the story variable between the parenthesis below
    storyMaker:Write()
end
  1. 等号の後に、「storyMaker:GetInput()」 と入力します。コードはそのまま入力し、大文字も一致させなければなりません。
while playing do
    storyMaker:Reset()

    -- Code story between the dashes
    -- =============================================
    local name1 = storyMaker:GetInput()

    -- =============================================

    -- Add the story variable between the parenthesis below
    storyMaker:Write()
end

質問の入力

変数には、小さな数字、ブール値、文字列など、さまざまな種類のデータを格納することができます。文字列型の変数は、文章全体を格納することもできます。文字列型変数は、常に「 “like this” 」引用符で囲まれているので、簡単に見つけることができます。

プレイヤーへの質問は、文字列型変数になります。

  1. GetInput()で、括弧の間をクリックします。中に、引用符で囲まれた質問を入力します。
    -- Code story between the dashes
    -- =============================================
    local name1 = storyMaker:GetInput("What is your favorite name?")

    -- =============================================
end
モバイルバージョンを終了