So I am trying to return to a class, from another class, and have it use
the value of an array that I want it to.
Prompts the user to give a number, hence if action == “1” etc.
action = $stdin.gets.chomp
if action == “1”
return ‘Death.@@ways_to_die.index “0”’
elsif action == “2”
return ‘HiddenTrapdoor’
else
return ‘Death.@@ways_to_die.index “1”’
end
^^^I just winged it here. Feel free to criticize.
From the class it is returning to, ‘Death’
For the sake of space I changed the values in the array to basic
numbers.
class Death < Scene
@@ways_to_die = [
“0”,
“1”,
“2”,
“3”,
“4”,
“5”,
“6”
]
def enter()
case
when @@ways_to_die.index “0” == true
@@puts ways_to_die[0]
when @@ways_to_die.index “1” == true
puts @@ways_to_die[1]
end
end
end
I spent 15 hours yesterday learning about arrays, hashes and classes,
and I would like to know how to do this, if at all possible. Any
help/advice would be greatly appreciated.