On 27.08.2008 14:55, Chris Bailey wrote:
>  I've been trying to solve the problem in the following bit of code for
> quite some time now with no luck. The unexpected kELSE error is occuring
> in the commented line. $map is a multi-dimensional array and the
> makeshift iterator works properly without the if/else statement. Any
> ideas?
> 
> def pmap
>     input = gets.downcase.chomp
>     if input == "exit"
>   $plrObj.save
>   puts "Exiting..."
>   $running = false
>     else
>   buf = ""
>   z = 0
>   $map.each do |x|
>       x.each do |y|
>     if z < 5
>         buf = buf + y.to_s
>         z++
>     else
>         buf = buf + "\n"
>         z = 0
>     end
>       end
>   end
>   puts buf
>     end
> end

Apart from the ++ issue you might want to change other things as well. 
First of all, you can use "buf += y.to_s" but this is less efficient 
than "buf << y.to_s".

Then, you are skipping every fifth element.  Is this really what you want?

Finally, if you are printing to console anyway direct printing is more 
efficient.  So I am assuming that you probably rather want something 
like this:

def pmap
   input = gets.downcase.chomp
   if input == "exit"
     $plrObj.save
     puts "Exiting..."
     $running = false
   else
     z = 0
     $map.each do |x|
       x.each do |y|
	print y

	if z >= 5
	  puts
	  z = 0
	end
       end
     end
     puts unless z == 0
   end
end

Kind regards

	robert