Unexpected end-of-input, expecting keyword_end

class Daskana_Environmental_Factors #0

def initialize(event_id, coverage)#1
@coverage = coverage #2
@event_id = event_id #2
@enemy_id = 0 #2
gets #2
@i = 1 #2
while @i <= $game_map.events.count do #2
if
$game_map.events[@i].instance_variable_get("@event").name.start_with?(“Minion”)
#3
@enemy_id =
$game_map.events[@i].instance_variable_get("@event").id #4
end #3
@i += 1 #3
end #2
end #1
#if there is something ground tile
def cover(coverage) #1
if @coverage > 0 #2
#if its tile coverage is a 1
if @coverage == 1 #3
#if the player is crouching
if $game_player.self_switch[1] == true #4
#character left, enemy right == y
if $game_player.x < $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #6
if $game_player.y == if $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character right, enemy left == y
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y == $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down, enemy up == x
if $game_player.x == $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up, enemy down == x
if $game_player.x == $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down and right, enemy up and left
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up and right, enemy down and left
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up and left, enemy down and right
if $game_player.x < $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down and left, enemy up and right
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
if $game_player.self_switch[1] == false #4
#character left, enemy right == y
if $game_player.x < $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #6
if $game_player.y == $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character right, enemy left == y
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y == $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down, enemy up == x
if $game_player.x == $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up, enemy down == x
if $game_player.x == $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down and right, enemy up and left
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up and right, enemy down and left
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character up and left, enemy down and right
if $game_player.x < $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #6
if $game_player.y < $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
#character down and left, enemy up and right
if $game_player.x > $game_map.events[@event_id].x #5
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #6
if $game_player.y > $game_map.events[@event_id].y #7
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #8
puts “target is out of line of sight” #9
end #8
end #7
end #6
end #5
end #4
end #3
if @coverage >= 2 #3
#if player is to the right and enemy to the left with los
coverage
#between them.
if $game_player.x < $game_map.events[@event_id].x #4
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #5
if $game_player.y == $game_map.events[@event_id].y #6
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is to the left and enemy to the right with los
coverage
#between them.
if $game_player.x > $game_map.events[@event_id].x #4
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #5
if $game_player.y == $game_map.events[@event_id].y #6
if $game_map.events[@enemy_id].y ==
$game_map.events[@event_id].y #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is below and enemy is above with los coverage
#between them.
if $game_player.y > $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #5
if $game_player.x == $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is above and enemy is below with los coverage
#between them.
if $game_player.y < $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #5
if $game_player.x == $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x ==
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is above and to the left, while enemy is below and
#to the right with los coverage between them.
if $game_player.y < $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #5
if $game_player.x < $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is above and to the right, while enemy is below and
#to the left with los coverage between them.
if $game_player.y < $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y >
$game_map.events[@event_id].y #5
if $game_player.x > $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is below and to the right, while enemy is above and
#to the left with los coverage between them.
if $game_player.y > $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #5
if $game_player.x > $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x <
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
#if player is below and to the left, while enemy is above and
#to the right with los coverage between them.
if $game_player.y > $game_map.events[@event_id].y #4
if $game_map.events[@enemy_id].y <
$game_map.events[@event_id].y #5
if $game_player.x < $game_map.events[@event_id].x #6
if $game_map.events[@enemy_id].x >
$game_map.events[@event_id].x #7
puts “target is out of line of sight” #8
end #7
end #6
end #5
end #4
end #3
end #2
end #1
end #0


I’ve been pondering this one all day, and I can’t figure out why when I
run this code… it is asking for an addition end… even though i closed
the class. my commenting after each line is my indentations as I become
frustrated with this bug I tried to see if there was a missing end…
“and” I have been unable to find the answer, there has to be something
incorrectly ended

Every beginer in ruby has had this issue lmost one time…

I see two kind of response : refactory or use editor which known ruby:

  • big function are bad, so explode cover() in function of max 20 lines
  • use editor with code folding :
    notepad++, sublime
    eclipse with ruby plugin/netbeans…

Or search manually by dichotomy : copy/delete/test/past :
delete contains of cover() , see if ok (run ruby with your source)
restore code deleted
if ok delete part of body
if nok, search outside if cover()
… recursively

If you delete all those interior if statements you are left with:

def cover(coverage) #1
if @coverage > 0 #2
#if its tile coverage is a 1
if @coverage == 1 #3
#if the player is crouching
if $game_player.self_switch[1] == true #4
#character left, enemy right == y
#character right, enemy left == y
#character down, enemy up == x
#character up, enemy down == x
#character up and right, enemy down and left
#character up and left, enemy down and right
#character down and left, enemy up and right
if $game_player.self_switch[1] == false #4
#character left, enemy right == y
#character down, enemy up == x
#character up, enemy down == x
#character down and right, enemy up and left
#character up and right, enemy down and left
#character up and left, enemy down and right
#character down and left, enemy up and right
end #4
end #3

You have two if-statements labeled #4, yet only one
end labeled #4.

Adding labels was a bad idea. Why do you think that adding labels v.
writing end is any different? You can only make mistakes with end, but
not with labels?

After you write about 10 - 15 lines of code you should try running it,
correct any mistakes, then write 10-15 lines more. You NEVER write
5,000 lines of code, then run it and wonder what the 200 errors are all
about.

Your code looks like a model representing a DNA strand–which is not
good. Computers are good at repetition, which is good, because humans
are not good at it.