意外的tSTRING_BEG,期望keyword_do和用户提示不起作用

时间:2015-06-20 23:28:57

标签: ruby

除了标题中的错误外,我还得到:

  

C:/ Users / Owner / Documents / Wyncode / unterminated string遇到file.rb:20:语法错误,意外(arg,期待keyword_do或' {'或'( '       放("僵尸在城堡里...             ^   [完成时间为0.3秒,退出代码为1]

当我提示用户回答时,我的终端在继续之前没有要求我回答。

这是我的代码:

name.Capitalize = {"1" => "Mario",
        "2" => "Luigi",
        "3" => "Kirby",
        }
    puts "Zombie apocalypse"
    puts "will you survive?"

def character (prompt, options)
    puts = "who will you be?"
    options = "Mario, Trump, Fox"
    character = gets.chomp.downcase
until options.include? character
end
end

puts "ok #{name} all three of you run out of peach's castle which has been overrun"

if character = #{Mario} || #{Luigi} || #{kirby}
    puts ("zombies are in the castle grounds, there are weapons over the bridge")
    puts "What do you do, charge through or sneak?"
    x = gets.chomp.downcase
            if x == "sneak"
                puts "oh you died"
            if x == "charge through"
                puts "the zombies tumbled over the bridge's edge, you made it safe and sound"
            else
                puts "you did nothing and were eaten alive by Princess Peach"
        end
    end

1 个答案:

答案 0 :(得分:2)

你在20号线上使用过:

    puts ("zombies are in the castle grounds, there are weapons over the bridge")

可以通过两种方式修复:

要么:

    puts "zombies are in the castle grounds, there are weapons over the bridge"

或者:

    puts("zombies are in the castle grounds, there are weapons over the bridge")

尽管如此,它可以帮助你摆脱那个特定的错误,一个接一个地会出现其他错误。为什么?因为,代码中存在许多错误。

我很佩服你的热情。你正在学习编程的第一周,而且你已经开始开发动作冒险游戏,哇。可悲的是,除非你学习手艺的基本知识,否则没有多少激情可以帮助你实现任何目标。我建议你买一本关于Ruby的好书。正确阅读并正确理解。

祝你好运。