Set Event speed and frequency with script

I am new to using VX Ace and am creating some events and enhancing them with script as needed. I have run into a situation where I want to dynamically set the speed and frequency of 4 events. I have 4 variables to hold the speed and 4 variables to hold the frequency of the 4 events. I choose random values for each variable and I want to set the speed and frequency of the 4 events at once.

Pseudocode would go like this:

speed1 = random number between 1 and 6

speed2 = random number between 1 and 6

speed3 = random number between 1 and 6

speed4 = random number between 1 and 6

freq1 = random number between 1 and 5

freq2 = random number between 1 and 5

freq3 = random number between 1 and 5

freq4 = random number between 1 and 5

event1.speed = speed1

event2.speed = speed2

event3.speed = speed3

event4.speed = speed4

event1.frequency = freq1

event2.frequency = freq2

event3.frequency = freq3

event4.frequency = freq4

I know I can reference the event via script like so:

$game_map.events[event_id]But, I want to do something like this:

$game_map.events[event_id].move_speed = $game_variables[1]$game_map.events[event_id].frequency = $game_variables[2]Does anyone know the properties to reference here?

Also, does anyone know of some good resources to help me understand the game engine. I am learning Ruby, but as far as the object model of the engine itself, is there any type of good object reference out there anywhere? I have found some snippets and have learned from those, but a broader scope would help me grasp the engine.

Thanks!
You can use a Set Move Route to change the speed and frequency. Unfortunately neither allow variables, so you have 2 options:

Use nested conditions along with move routes and do them one at a time:

Condition: Game Variables [0001: Speed1] == 1 Set Move Route (Event 1): Speed: 1Else Condition: Game Variables [0001: Speed1] == 2 Set Move Route (Event 1): Speed: 2 Else Condition: Game Variables [0001: Speed1] == 3 Set Move Route (Event 1): Speed: 3... and so on ...Condition: Game Variables [0002: Frequency1] == 1 Set Move Route (Event 1): Frequency: 1... and so on ...... then do the same for the remaining events ...As you can see, there'll be a lot of conditions and move routes there - the more events you want to affect, the longer it will get.The easier approach is to just go into Game_CharacterBase, and where it's got move_speed and move_frequency as attr_reader, change them both to be attr_accessor instead. Then you can just do this:

$game_map.events[1].move_speed = $game_variables[1]$game_map.events[1].move_frequency = $game_variables[2](You'll need to add line breaks where I have, otherwise the game will crash)Remember though, if anything happens to change conditions so a different page on those events becomes active, the speed and frequency will change back to whatever is on the active tab.
You won't be able to modify an event's move speed or move frequency property directly unless you do a bit of script editing (change attr_reader to attr_accessor for certain properties in Game_CharacterBase) since they're only readable.


Move Speed:


$game_map.events[event_id].instance_eval("@move_speed = value")


Move Frequency:


$game_map.events[event_id].instance_eval("@move_frequency = value")


Edit: Ninja'd.
Actually, it's easier than that.

You can use a Set Move Route and select the event you want to change. Then add two Script movement commands as follows:

Code:
Set Move Route: [EV001]              : $> Script: @move_speed = $game_variables[1]              : $> Script: @move_frequency = $game_variables[2]
You don't NEED to make the variables attr_accessor, because the Set Move Route is being called BY the event, so they are within the scope of the Script movement command.
I thought of the massive conditional branch, but wanted it to be a little cleaner and learn a little scripting along the way. Two birds with one stone.

Thanks to you all! I'll give it a shot.
Post back whether any of these work or not, so we know whether to leave the topic open or to close it up 🙂
You won't be able to modify an event's move speed or move frequency property directly unless you do a bit of script editing (change attr_reader to attr_accessor for certain properties in Game_CharacterBase) since they're only readable.

Move Speed:

$game_map.events[event_id].instance_eval("@move_speed = value")

Move Frequency:

$game_map.events[event_id].instance_eval("@move_frequency = value")

Edit: Ninja'd.
Could also set the property directly using `instance_variable_get` or set so you don't need readers or accessors.

Code:
$game_map.events[i].instance_variable_get(:@move_speed)    #returns the value of @move_speed$game_map.events[i].instance_variable_set(:@move_speed, 4) #sets the value of @move_speed to 4
Actually, it's easier than that.

You can use a Set Move Route and select the event you want to change. Then add two Script movement commands as follows:

Set Move Route: [EV001] : $> Script: @move_speed = $game_variables[1] : $> Script: @move_frequency = $game_variables[2]You don't NEED to make the variables attr_accessor, because the Set Move Route is being called BY the event, so they are within the scope of the Script movement command.
This did the trick. The variable scope makes sense, too. Thanks for sharing your knowledge, all!
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/set-event-speed-and-frequency-with-script.15177/