Note that there are some explanatory texts on larger screens.

plurals
  1. POnoMethod error in Beginning Ruby by Peter Cooper chapter 6 dungeon game
    primarykey
    data
    text
    <p>I am stuck on the part in chapter 6. It is a dungeon text-adventure game with rooms and a player that moves around. I keep getting a noMethod error for the .detect method used in the find_room_in_dungeon method. I assume that I am probably missing something but I just can't figure out what. I would really appreciate if someone could help me out. thanks.</p> <pre><code>class Dungeon attr_accessor :player def initialize(player_name) @player=Player.new(player_name) @room = [] end def add_room(reference, name, description, connections) @room &lt;&lt; Room.new(reference, name, description, connections) end def start(location) @player.location=location show_current_description end def show_current_description puts find_room_in_dungeon(@player.location).full_description end ### def find_room_in_dungeon(reference) @rooms.detect { |room| room.reference == reference } end ### def find_room_in_direction(direction) find_room_in_dungeon(@player.location).connections[direction] end def go(direction) puts "you go " + direction.to_s @player.location= find_room_in_direction(direction) show_current_description end class Player attr_accessor :name, :location def initialize(name) @name = name end end class Room attr_accessor :reference, :name, :description, :connections def initialize(reference, name, description, connections) @reference =reference @name =name @description=description @connections=connections end def full_description @name + "/n/n you are in" + @description end end end my_dungeon= Dungeon.new("adventurer") my_dungeon.add_room(:largecave, "large cave", "a very large cave", {:west =&gt; :smallcave}) my_dungeon.add_room(:smallcave, "smallcave", "a small cave", {:east =&gt; :largecave}) my_dungeon.start(:largecave) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload