There are several problems here, and usually we ask people what they want to do instead of how they want to do it, because this sounds like something that is better handled by a completely different structure.
The engine has different interpreters for different sequences, and knowing what you want to do is half way to the solution.
One option is to alias the loading and initialisation of the map to connect the function to your code, but then the code will be running in the engine and it would be different to have it multiple time on the map.
The second option is to link to the game_interpreter that handles the events on the map and the common events while being on the map.
In this case you simply make an autorun event call a script command. This can do everything you want, but only for a single event.
Creating new events is NOT simple - you can search for clone event scripts to learn how to copy an existing event. But without knowing what kind of use you have for those events, we can't even tell if that will work like you expect it to work.
So please add a description of what you want to do here instead of how you want to do it.
Sorry, I suppose I wasn't very clear about what I was asking for. I'm *not* looking to have the script create the events. I will manually create the events with the regular RM interface for creating events. What I'm trying to do is have that event, when triggered, call a method of an object. And I might make (again manually) 3 of these events, each of which should refer to their own instance of the class when calling the method.
So, taking my example code from above, but extending it a bit. Let's say I manually create 3 NPCs. I would like for each one to have an instance of `Foo` it's connected to. Then when you talk to the NPC, the `add()` method for the `Foo` instance connected to that NPC will be called.
Of course, this is just another minimal example I thought would be simpler to give the answer to then my full problem. What I'm trying to implement is a puzzle, part of which involves a block pushing puzzle. But there are blocks of different colors. When a colored block is pushed, all blocks of that color on the map move in the same direction (if able).
I had intended to implement this by creating a class which when initialized stored the color of the block and it's corresponding event ID. Then it would have a `pushed()` method, which when called will get the full list of block IDs with the same color and set the move route for each of their events to match the direction of the push.
no need for something like that, this can be done by pure eventing as long as you create all events beforehand and they don't change their colors or something like this.
when triggered, you usually move the block by set move route command for one step into the given direction.
However, the set move route can be targeted on any event - and if you create all events manually, then you know which other events are of the same color. So simply add more set move routes, targeted to all events of the same block color, to where you have the move command.
This would be the pure eventing method.
However, if you have too many colors and to many blocks on too many different maps so that you want to make it simpler by script, use a different approach:
Place a comment command on the top of each event containing your color name - there is script code to check the inside of comment commands, several scripts use that to get data to events because events in VXA don't have a notebox. Search for the more complex event-handling scripts on the master script list to learn how that is done, I think several scripts from Victor and a few others do this.
Then, in the event when the move is triggered, call a static function that loops through all events on the map checking which ones have the given string in the comment, and move them by set move route-equivalent of the command.
Absolutely no need to add new methods to their objects for this.
Thanks! I'll certainly look into the using the comment command approach (I'll have enough of these that I would find it very tedious to manually setup those move routes).
I had intended to extend this with blocks that switch colors among other unique cases. Is there simple ways to add in that functionality through the event setup? I was also going to extend it with these blocks teleporting when hitting certain spaces, sliding on ice, etc. But I was just going to start with the color part.
Lastly, is it difficult to do the kind of event-object linking I was suggesting? I'm sure this is just from my from my lack of familiarity with the event editor, but having the classes in ruby be the workhorse seems so easy to me, while the event editor seems very cumbersome. That is, I feel that when I want to add the color switching (or other new things) I would immediately know how just make an object call the right method to change things so that the setup is different. Where I would have to come back and ask again for the event editor. Again, I'm sure it's just the familiarity with the system, but I already know how to do everything in the programming environment. That is, other than communicate that information to and from the RM engine, though I think the to-RM direction I can pretty easily see good examples of already (just having the object store the event ID and what not). I always think in terms of everything I work with being a instance of an object, and I think that form of working with the event would be most intuitive to me. Whenever I want something to happen in RM, I immediately how I would use the event as if it were an object.
In any case, thanks again for the help!
It's not so much the difficulty in programming it, it is preventing unintended side effects. All movement is handled inside the main game loop, and the set move route command and its scripts call equivalent will allow the engine to handle everything correctly.
Making your own functions for manipulating data will prevent the engine from checking the datails, and you might end up with a broken main loop - which is not easy to fix.
So if you add your own classes, you need to know when to call the existing functions and when to add your own, and that takes some familiarity with how the engine handles everything.