RGSS3 - Methods in script editor as opposed to in events

● ARCHIVED · READ-ONLY
Started by shaynec1981 11 posts View original ↗
  1. So I'm attempting to run some custom move commands through scripting instead of the 'Set Move Route' command in an event using this script call:

    Spoiler
    move_route = RPG::MoveRoute.new
    move_route.repeat = false
    move_route.skippable = true
    m = RPG::MoveCommand.new
    m.code = 1
    move_route.list.insert(0,m.clone)
    $game_map.events[eventid].force_move_route(move_route)
    Now if I go directly into an event and use the script call command, this works perfectly fine. However if I add this same exact script call to a new class (which does inherit Game_Character), it throws an undefined force_move_route method error. Can someone please explain to me why this is? I assumed since this class inherits Game_Character that it would know what force_move_route was.
  2. Are you sure that force_move_route was on Game_Character (or it's superclass)? I'm not on my RM right now so I cannot check
  3. Yes, that method is definitely in Game_Character
  4. Where did you add your code?

    Let you print out $game_map.events, before you call your moveroute. Maybe there is no Event with the event id you have specified when you call the force route method.
  5. what is eventid? There's no such thing in the default scripts.


    It would be @id or @event.id but that would only be valid in the Game_Event class (should not go into Game_Character as not all Game_Characters HAVE an event id)
  6. Sorry forgot to mention that eventid is a local variable:

    eventid = $game_map.event_id_xy($game_variables[37], $game_variables[38])

    Simply referring to the event at this particular location.
  7. can you show us the full error message and the custom class that you made?

    and yeah, if the "event" that ur trying to do the move route is of the custom class, then it could be well possible that it doesn't have an eventid and/or isn't defined inside the $game_map.events array...

    Please show us how you're calling the methods exactly, both using the event and the custom class too.
  8. Ok, trying to write a simple projectile script so you know where I'm coming from for starters. I know projectile scripts already exist but I'm wanting to do this to learn a bit more about scripting.

    Firstly, when a key is pressed this snippet is ran in a common event:

    Spoiler
    spawn_event(34, $game_variables[83], 9, $game_variables[84], $game_variables[85])
    @shurikentoss = Shuriken_Toss.new
    spawn_event is simply:

    Spoiler
    def spawn_event(spawn_from_map_id, _map_id, _event_id, _x, _y)
      map = load_data(sprintf("Data/Map%03d.rvdata2", spawn_from_map_id))
      event_id = $game_map.events.keys.max + 1
      preprocess = map.events[_event_id]
      preprocess.id = event_id
      event = $game_map.events[event_id] = Game_Event.new(_map_id, preprocess)
      sp_map = SceneManager.scene.instance_eval('@spriteset')
      sp_map_char_sprs = sp_map.instance_eval('@character_sprites')
      sp_map_view_1 = sp_map.instance_eval('@viewport1')
      sp_map_char_sprs.push(Sprite_Character.new(sp_map_view_1, event))
      event.moveto(_x, _y)
    end
    For the projectile script I have started:

    Spoiler
    class Shuriken_Toss < Game_Character
     
      def initialize
        if $game_variables[88] == 2
          south_check
        elsif $game_variables[88] == 4
          west_check
        elsif $game_variables[88] == 6
          east_check
        elsif $game_variables[88] == 8
          north_check
        end
      end
     
       def south_check
        $game_variables[37] = $game_variables[84] # current event x pos equal to player pos
        $game_variables[38] = $game_variables[85] # current event y pos equal to player pos
        $game_variables[36] = $game_variables[85] # 'next tile' collision check variable
        $game_variables[36] += 1 # looks at next y pos
        eventid = $game_map.event_id_xy($game_variables[37], $game_variables[38])
        if passable?($game_variables[37], $game_variables[36], 2) == true
          move_route = RPG::MoveRoute.new
          move_route.repeat = false
          move_route.skippable = true  
          m = RPG::MoveCommand.new
          m.code = 1
          move_route.list.insert(0,m.clone)
          $game_map.events[eventid].force_move_route(move_route)
        end
      end
     
      def west_check
      end
     
      def east_check
      end
     
      def north_check
      end
     
        
    end
    *Edit - Left out a line in the class.

    Whenever I put a p eventid just after the eventid variable is created and set, it shows up with the correct event id in the console so I'm pretty positive that this is being passed later in the method.
  9. And what happens when you do that? 
  10. Same error. That line I missed in that post was actually in the code, just forgot to put it in the spoiler tag.
  11. What's the exact error message? The full one... A screenshot of it would be nice. I'm sure I already asked for it before. :)