A* Pathfinding Problem

Started by Yin, October 10, 2009, 05:03:43 pm

Previous topic - Next topic

Yin

October 10, 2009, 05:03:43 pm Last Edit: October 12, 2009, 06:08:59 pm by Yin
Sorry guys, I don't know how I did it, but I fixed it!
Just realized that my post didn't fit.
I fixed it.
Ok, I made an event and in the move route I have
Code: text
node = Node.new(55, 16); char = 113; path = A_Star_Pathfinder.new(node, char, false); path.generate_path

in a script call. Then turn up and wait 300 right after. Everything works fine until the event gets to 55, 16. It doesn't turn up or wait 300. Then an error pops up with this
line 738 No Method error occured
undefined method 'list'for nil:nilclass

Code: text
  #--------------------------------------------------------------------------
 # * Move Type : Custom (move event, pattern, etc.)
 #   Note: The script overwrites this method, which _might_ lead to
 #   compatibility problems with other scripts. You can remove this
 #   method to fix any such problem, but the character won't be able
 #   to detect the need to recalculate the path.
 #--------------------------------------------------------------------------
 def move_type_custom
   # Interrupt if not stopping
   if jumping? or moving?
     return
   end
   # For each move command starting from the index
   while @move_route_index < @move_route.list.size <----------------------------------------------------Error is on that line!
     # Get the move command at index
     command = @move_route.list[@move_route_index]
     # If command code is 0 (end of list)
     if command.code == 0
       # If [repeat action] option is ON
       if @move_route.repeat
         # Reset move route index to the top of the list
         @move_route_index = 0
       end
       # If [repeat action] option is OFF
       unless @move_route.repeat
         # If move route is forced and not repeating
         if @move_route_forcing and not @move_route.repeat
           # The move route is no longer forced (moving ended)
           @move_route_forcing = false
           # Restore original move route
           @move_route = @original_move_route
           @move_route_index = @original_move_route_index
           @original_move_route = nil
### CODE ADDED HERE ############################################################
           # If there was a path to follow and we reached goal
           if @a_star_paths[0]
             if self.x == @a_star_paths[0].goal_node.x and
                 y == @a_star_paths[0].goal_node.y
               # Call the reach method if one was provided
               if @a_star_paths[0].reach_method
                 @a_star_paths[0].reach_method.call
               end
             end
             follow_next_path
           end
### ADDED CODE ENDS ############################################################
         end
         # Clear stop count
         @stop_count = 0
       end
       return
     end # if command.code == 0
     # For move commands (from move down to jump)
     if command.code <= 14
       # Branch by command code
       case command.code
       when 1  # Move down
         move_down
       when 2  # Move left
         move_left
       when 3  # Move right
         move_right
       when 4  # Move up
         move_up
       when 5  # Move lower left
         move_lower_left
       when 6  # Move lower right
         move_lower_right
       when 7  # Move upper left
         move_upper_left
       when 8  # Move upper right
         move_upper_right
       when 9  # Move at random
         move_random
       when 10  # Move toward player
         move_toward_player
       when 11  # Move away from player
         move_away_from_player
       when 12  # 1 step forward
         move_forward
       when 13  # 1 step backward
         move_backward
       when 14  # Jump
         jump(command.parameters[0], command.parameters[1])
       end
       # If movement failure occurs when [Ignore if can't move] option is OFF
       if not @move_route.skippable and not moving? and not jumping?
### CODE ADDED HERE ############################################################
         # If there's a path but it couldn't be followed (probably because
         # another character blocked it)
         if @a_star_paths[0] and
            A_Star_Pathfinder::COLLISION_WAIT >= 0 and
            (A_Star_Pathfinder::COLLISION_LIMIT < 0 or
            @a_star_paths[0].collision_counter <= A_Star_Pathfinder::COLLISION_LIMIT)
           # Setup path again to update starting location.
           # original goal node is used because pathfinding changes
           # the goal node to current node
           goal = @a_star_paths[0].original_goal_node
           char = @a_star_paths[0].character
           range = @a_star_paths[0].range
           close = @a_star_paths[0].get_close
           reach = @a_star_paths[0].reach_method
           fail = @a_star_paths[0].fail_method
           counter = @a_star_paths[0].collision_counter
           # Find another path to goal
           @a_star_paths[0] = A_Star_Pathfinder.new
           @a_star_paths[0].setup(goal, char, range, close, reach, fail)
           @a_star_paths[0].calculate_path
           @a_star_paths[0].generate_path(false)
           @a_star_paths[0].collision_counter = counter + 1
           force_move_route(@a_star_paths[0].route) if @a_star_paths[0].found
           # Wait a bit before starting to follow the new path
           @wait_count = A_Star_Pathfinder::COLLISION_WAIT
           return
         elsif @a_star_paths[0]
           # If collision wait is -1 or reached collision limit,
           # stop character and call any fail method
           @move_route_index = @move_route.list.size
           if @a_star_paths[0].fail_method
             @a_star_paths[0].fail_method.call
           end
           follow_next_path
         end
### ADDED CODE ENDS ############################################################
         return
       end
       # Advance index
       @move_route_index += 1
       return
     end # if command.code <= 14
     # If waiting
     if command.code == 15
       # Set wait count (from provided parameter)
       @wait_count = command.parameters[0] * 2 - 1
       @move_route_index += 1
       return
     end # if command.code == 15
     # If direction change (turning) command
     if command.code >= 16 and command.code <= 26
       # Branch by command code
       case command.code
       when 16  # Turn down
         turn_down
       when 17  # Turn left
         turn_left
       when 18  # Turn right
         turn_right
       when 19  # Turn up
         turn_up
       when 20  # Turn 90° right
         turn_right_90
       when 21  # Turn 90° left
         turn_left_90
       when 22  # Turn 180°
         turn_180
       when 23  # Turn 90° right or left
         turn_right_or_left_90
       when 24  # Turn at Random
         turn_random
       when 25  # Turn toward player
         turn_toward_player
       when 26  # Turn away from player
         turn_away_from_player
       end
       @move_route_index += 1
       return
     end # if command.code >= 16 and command.code <= 26
     # If other command (commands that don't 'return')
     if command.code >= 27
       # Branch by command code
       case command.code
       when 27  # Switch ON
         $game_switches[command.parameters[0]] = true
         $game_map.need_refresh = true
       when 28  # Switch OFF
         $game_switches[command.parameters[0]] = false
         $game_map.need_refresh = true
       when 29  # Change speed
         @move_speed = command.parameters[0]
       when 30  # Change freq
         @move_frequency = command.parameters[0]
       when 31  # Move animation ON
         @walk_anime = true
       when 32  # Move animation OFF
         @walk_anime = false
       when 33  # Stop animation ON
         @step_anime = true
       when 34  # Stop animation OFF
         @step_anime = false
       when 35  # Direction fix ON
         @direction_fix = true
       when 36  # Direction fix OFF
         @direction_fix = false
       when 37  # Through ON
         @through = true
       when 38  # Through OFF
         @through = false
       when 39  # Always on top ON
         @always_on_top = true
       when 40  # Always on top OFF
         @always_on_top = false
       when 41  # Change Graphic
         # Can't change into a tile
         @tile_id = 0
         @character_name = command.parameters[0]
         @character_hue = command.parameters[1]
         # Update direction
         if @original_direction != command.parameters[2]
           @direction = command.parameters[2]
           @original_direction = @direction
           @prelock_direction = 0
         end
         # Update frame
         if @original_pattern != command.parameters[3]
           @pattern = command.parameters[3]
           @original_pattern = @pattern
         end
       when 42  # Change Opacity
         @opacity = command.parameters[0]
       when 43  # Change Blending
         @blend_type = command.parameters[0]
       when 44  # Play SE
         $game_system.se_play(command.parameters[0])
       when 45  # Script
         result = eval(command.parameters[0])
       end
       # Update move_route_index and move to next move command in the list
       @move_route_index += 1
     end # if command.code >= 27
   end # while @move_route_index < @move_route.list.size
   #rescue <------------------------------------------------------------------------------- My rescue
 end

When I use rescue, it doesn't crash, but it doesn't finish the move route either. It does the script call and just stays there with no error.

I'd really like to get this working and any help would be appreciated. Thank you to anyone who is willing to help me with this.
Newly formed MUGEN, RPG Maker, and BOR forum.
http://cavernofcreativity.com
Opening in September
My Partner in crime = TREXRELL