Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[SOLVED]Need help with events in RGSS =/

Ares

Member

I wanted to make a script that goes through all events in all maps, and checks if it's name is equal to a specific string.
And if it ís equal, store the x, y and map of that event in an Array in a Hash.
Something like this (I guess):
[rgss]module Database
begin
for i in 0..ALL_EVENTS
 if i.name == "String"
  @hash = [x, y, map]
 end
end
@hash.compact
end
 
def Database.events
 return @hash
end 
end
[/rgss]

But I didn't find a way to iterate through all events on all maps...

Note: I am aware of the fact that, if you want to check 200 events on 999 maps it will take a long time and cause great lag, but that is not a problem at this point.
I don't know whether this is even possible. Please help me out here!

Thanks in advance
 
To go through every event in every map, you'd want something along these lines:
Code:
  MATCH = "String"

  def setup

    @data = []

    for map_id in 0...999

      filename = sprintf("Data/Map%03d.rxdata", @map_id)

      if FileTest.exist?(filename)

        map = load_data(filename)

        for i in map.events.keys

          if @map.events[i].name == MATCH

            @data.push([map_id, @map.events[i].x, @map.events[i].y])

          end

        end

      end

    end

  end

Obviously I wasn't sure what you wanted to use as a key for the hash, so I just pushed it all into an array. And as far as I could tell, there's no easy way to get a list of all the maps in the game, so I just had to check maps 001 thru 999 and see if they exist.

Didn't really test it outside of making sure it compiles (once I put it in a class), but should work in theory.
 
Rach, you could probably do a .size on the array in MapInfos.rxdata, or loop through the array indexing all the non-nil objects.
(probably more work than it's worth...)

I'm guessing this is a development tool, not part of a working game. ??
although I can imagine how it could be used to cast some sort of 'akasha' spell, or to display a bunch of 'somethings' on a world map...

It occurred to me to quit looping after FileTest returns false, but then it would quit if he had deleted a map...

Be Well
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top