• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Checking for event names in script help

Rayd12smitty

Shadow Maker
645
Posts
12
Years
    • Seen Feb 21, 2016
    I am trying to make something run for every event on the map, but only if that event has a certain name. I have this
    Code:
        for event in 0...$game_map.events.length
          pbMoveRoute($game_map.events[event],[PBMoveRoute::StepAnimeOn])
        end
    which works perfectly for every event on the map. I only want the events named "Poke" though. I tried this
    Code:
        for event in 0...$game_map.events.length
          if event.name=="Poke"
            pbMoveRoute($game_map.events[event],[PBMoveRoute::StepAnimeOn])
          end
        end
    I get an error. I have tried doing other methods with using $game_map.events.values instead but I can't get any events to move when I do that, although the game doesn't crash. I'm kinda lost here. Can anyone help?
     

    ~JV~

    Dev of Pokémon Uranium
    684
    Posts
    16
    Years
  • the variable is returning a number between 0 and the total number of events on the map, so trying to get a .name from it won't work. What you should do to get the actual event is use:

    Code:
    for event in $game_map.events.values

    instead of:

    Code:
    for event in 0...$game_map.events.length
     

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    the variable is returning a number between 0 and the total number of events on the map, so trying to get a .name from it won't work. What you should do to get the actual event is use:

    Code:
    for event in $game_map.events.values

    instead of:

    Code:
    for event in 0...$game_map.events.length

    Alright I get no error now, but nothing happens. I took away the name check but the animation/move route doesn't happen on any of the events with or without the name check.

    This is the whole script
    Code:
      def update_stepping
        FollowingMoveRoute([PBMoveRoute::StepAnimeOn])
        for event in $game_map.events.values
          if event.name=="Poke"
            pbMoveRoute($game_map.events[event],[PBMoveRoute::StepAnimeOn])
          end
        end
      end

    You can ignore the FollowingMoveRoute part. I am trying to add something to the Following Pokemon script I am working on. This "update_stepping" is called whenever the map updates pretty much so it's constant. The update for the Following Pokemon sprite works perfectly. I want to make the same effect work for any event named "Poke"
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    It looks like you're getting confused about what you're looping through.

    Code:
    for event in $game_map.events.values
    event is an event. It's not a number. event.name works fine, because events have names, but $game_map.events[event] is nonsensical because it expects event to be a number and would give the event with that number.

    Replace $game_map.events[event] with event.
     

    Rayd12smitty

    Shadow Maker
    645
    Posts
    12
    Years
    • Seen Feb 21, 2016
    Thank you so much! I wasn't sure exactly what these values were or returned. I was just trying to look at other scripts and try to figure out how to make it run.
     
    Back
    Top