Lambda Lambda - 1 month ago 21
Ruby Question

Ruby - Equivalent to foreach

I'm working on a project in RMXP with Ruby scripts.

I create a table with id maps. I am now looking to go the table such that if the player enters one of the maps of the table, things happen.


Example of action: tMaps = [006, 008, 009]

If the hero is on the map 004, 005 ... it nothing happens If the hero
is on the map 006, Action


I hope this is feasible. If not, what other means I have in Ruby to find the maps and to assign actions?

PS I've traveled a bit, this wiki : http://fr.wikibooks.org/wiki/Programmation_Ruby/Contr%C3%B4le

Answer

Your list is wrong, I suppose you want integer : [6, 8, 9] not [006, 008, 009] (this is octal form)

tMaps = [6, 8, 9]

tMaps.each do
   |value| puts 'value : '+value.to_s
end

# or : 
for value in tMaps
   puts 'value : '+value.to_s
end