Set Event speed and frequency with script

Status
Not open for further replies.
Joined
Sep 27, 2012
Messages
3
Reaction score
0
Primarily Uses
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!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 
  • Like
Reactions: PK8

PK8

I sense there's something in the wind...
Veteran
Joined
Mar 17, 2012
Messages
1,220
Reaction score
152
Primarily Uses
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.
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
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.
 
Joined
Sep 27, 2012
Messages
3
Reaction score
0
Primarily Uses
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Post back whether any of these work or not, so we know whether to leave the topic open or to close it up :)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
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
 
Last edited by a moderator:
  • Like
Reactions: PK8
Joined
Sep 27, 2012
Messages
3
Reaction score
0
Primarily Uses
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!
 

Celianna

Tileset artist
Veteran
Joined
Mar 1, 2012
Messages
10,557
Reaction score
5,592
First Language
Dutch
Primarily Uses
RMMV
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.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top