Friday Script – Modern Algebra’s Messages Part II

If you want to get the most out of RPG Maker, learn Ruby. In the meantime, lots of talented scripters have done the work for you. Every Friday, The Iron Shoe features a fun script and goes into detail about how to use it. It also covers a little bit of Ruby each time so you can make even more out of the script.

Last week I talked about Modern Algebra’s ATS: Message Options script, and showed off just a bare handful of things it could do. Today, I want to show you a little modification that became necessary in Vidar.

The Problem With Spawning Events: Modern Algebra’s script uses in-dialogue codes to position the text-box. So, for example, \et[3] puts the message window about Event 3 on the current map. This is fine unless you don’t know the Event ID. How would that happen? Spawned events – if you’ve been following the blog, you know that most of the events in Vidar, including puzzle-components and quest items, are generated using a script once you hit “new game” to afford randomization. They aren’t hard coded into the map data.

And in fact, sometimes, quest items can appear in one of several maps. One example is Bernadett’s request that you find several ghosts throughout the ice cave. These ghosts – who want to talk to you and, thus, have message windows to contend with – can spawn anywhere in 6 maps. There’s no way in advance to know what to put in the brackets of \et[ ].

Because these are in-text code, not just script calls, we can’t do something like \et[@event_id].

Detour: These kinds of in-text codes are actually native to RPG Maker. You can do things like \N[x] to get the name of actor X, \P[x] for the name of the x’th party member, and critically, \V[x] is the same as $game_variables[x]. You can even nest these like you might actual script – \N[\V[x]] first looks up variable X, returns the result, and finds the name of the actor with the ID of that result.

The Problem With MA’s Script: So in theory, the above scenario can be fixed with an additional command in the event where we don’t know it’s ID ahead of time.

  1. Set variable 100 to @event_id
  2. Use \et[\V[100]] in the text to position the message window.

This nesting does not work in Modern Algebra’s script. Specifically, the script won’t know to look ahead before resolving the \et, so it’ll just assume \et[0].

Solution: Look for the following section of the code:

MAFixed2

This is where the code uses some regular expressions to try to find our in-text codes. Above all of it, we’re going to add a little catch.

while result[/\\V\[(\d+)\]/i]
    variable_id = $1.to_i
    result.sub!(/\\V\[(\d+)\]/i, $game_variables[variable_id].to_s)
end

That is, if you can find \V[], replace it with the value of that variable, and do so before resolving anything else. Our code looks like this now:

MAFixed1

And nesting variables into the Modern Algebra script will now work perfectly.

MAFixed3

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s