Checking Event Names with a Script Call (VX Ace)

Hello! I'm attempting to create a common event that changes the graphics of a somewhat large group of events on each map. The graphic change itself is simple- they turn, and this is handled by a separate script. However, these events in particular have Direction Fix set to ON- their graphics won't turn on their own. I want to give these events the same same- or the same but numbered, if using only a piece of the full name is possible- so that I can use a Script Call, possibly in a Conditional Branch, checking for their shared name, then turning Direction Fix OFF. Once the script has rotated everything, these events will have Direction Fix set back to ON.

It would go something like this, I believe.

Code:
mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new )

if event_name == ['example'] (not real code)
$game_map.events[evt].force_move_route(mr)
end

Any help, as always, will be appreciated.
Code:
event.name ~= /$regexp/i
?

with regular expressions you can pretty much punch any custom string out of another string.
and, it will take the result and save it for later, so you just call $1, $2, etc, and it will bring the found matches.

if $1 == nil, it didn't find anything

if you're numbering,....
Code:
event.name ~= /^(Event)_[\n{00-99}]/i
.... maybe? my $regexp is kind of rusty lately.... but, there are ways to scan for numbers, letters and everything
$1 will bring "Event", which is bracketed, if it's found, if the string is something like "Event_00" to "Event_99"

think about the basic "dir" instructions of DOS.
I.. erm, the oldest system I've used is Windows 95. I never had to use DOS.

I also don't know how to 'call' $1. I attempted:

Code:
mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new )

event.EXAMPLENAME ~= /$regexp/i
for event in $1
$game_map.events[evt].force_move_route(mr)
end

, but I crashed, with this error.

Game_Bug_011.png


It doesn't take a genius to tell I'm bad at coding, unfortunately.

Any ideas?
go into the help files and do a search for regular expressions.
it's all there.
Hmm, according to the help file, it's supposed to be "=~", and not "~=". I mean, I'm still crashing, but it's a different crash than before, so the difference clearly matters. Thought you should know. I'll keep reading up, though the help files aren't detailed enough, and the Ruby websites..
Code:
str =~ /^([1-9]\d*):(\w+)$/ && $2.size == $1.to_i

..I'm going to be here a while, haha.
in that example, str would probably be something like 3:ten.
(ten), $2, has 3 letters, which is the value of $1, which is at least one digit long.

*read the help files!*
where do you think *I* learned about Ruby?

here's a bit from CrystalNoel's XStats plugin
Code:
def xstat_modifier(stat)
    @note =~ /<STATE_XSTAT: #{stat} ([\+|\-]?\d+)(%?)>/i
    return [$1.to_i, $2]
  end

you have no idea the TIME it took me to come up with that expression.
I needed to check for positive and negative integers, and percentages.

that expression reads "From note, find tag <State_Xstat: name value> if any, with {name} given by parameter, store value as integer, with sign if included, as many digits as provided, and read for percentage. Return (value) as integer, and (percentage sign) if any"
I then check for $2, and turn $1 into percentage if required.
that instruction handles the entire extra stat sytem, and (stat) can be anything, so I had to scan for all possible variations.
I started reading the help file, couldn't make heads or tails of it, of course. I've been trying to learn from https://forums.rpgmakerweb.com/inde...troductory-guide-to-rgss-for-beginners.38900/, but I don't think it's sticking. I don't enjoy having to ask for help on here because I'm completely incompetent at writing code.

Code:
def xstat_modifier(stat)
    @note =~ /<STATE_XSTAT: #{stat} ([\+|\-]?\d+)(%?)>/i
    return [$1.to_i, $2]
  end

that expression reads "From note, find tag <State_Xstat: name value> if any, with {name} given by parameter, store value as integer, with sign if included, as many digits as provided, and read for percentage. Return (value) as integer, and (percentage sign) if any"
I then check for $2, and turn $1 into percentage if required.
that instruction handles the entire extra stat system, and (stat) can be anything, so I had to scan for all possible variations.

Like this. This means absolutely nothing to me, and it's not your fault at all. It's incredibly frustrating having to redesign an event over a dozen times because I can't write the script call on my own. I'll just use switches to do this, I guess. Don't waste any more time trying to help, I shouldn't have opened this thread. Sorry.


Edit: Melodrama.
@Robert-Character Creator I'd come at this a different way, using a very simple script call approach. I may not have understood your query fully, so I hope this isn't off the wall.

If I have understood correctly, you want a large number of events to do the same thing through the use of a Set Move Route command. For the sake of this example, let us say that one of those events has the event id 20. We will also say that the other events you want to replicate this have the ids of 17, 21, 34 and 87.

First do the Set Move Route command for event 20 e.g. Direction Fix OFF.
Immediately under that put in this script call. Type it exactly like this, except of course change [17, 21, 34, 87] in the first line and [20] in the second to the ids of the events in your game.

Code:
[17, 21, 34, 87].each do |event_id|
  $game_map.events[event_id].force_move_route($game_map.events[20].move_route)
end

All the events you put in that first line will then mimic what event 20 does.
Kes, that approach only works on sorted systems.
by the looks of it, he has it unsorted.

that's why the regular expression is better, because it's made to look at more general and undefined expressions.

(that or, you can just sort the whole system and be done with it...... )


OR, good ol' database query approach then?
Code:
$game_map.events.select{|ev|
  ev.name =~ /"Dummy"\s(\d+)/i ? $1.between?(0,99) : false}.each {|ev|
  ev.force_move_route($game_map.events[20].move_route)}

applies map events' number 20's (whomever that is) route to events in map *named* "Dummy 00" to "Dummy 99", which could be any id other than 20.
Sorry for the meltdown earlier; bad day, let's move on.

It's good to see you Kes, it's been a while. Gstv87 is right, my system isn't sorted, and even if it were, there's differing numbers of these events on each map, making things a bit more complicated.

I have events 19 and 20 set up to do the job. 19 goes first, turning off Direction Fix and changing these events' collision, then Heirukichi's script does its thing, and event 20 turns these events' Direction Fix back on.

Code_12.png


Still crashes, though.

Game_Bug_012.png
It crashes because everyone still keep forgetting that the @events variable in Game_Map is a hash and not an array.

If you just want the event objects, you can use:
$game_map.events.values.select {|ev| * code here * }

Or you can keep the code you have, just use |key,ev| instead of |ev| in it.

That code formatting hurts my eyes, btw. 😀
yep... I always forget it's a hash lol
replace
$game_map.events.values.select{}
instead of
$game_map.events.select{}

That code formatting hurts my eyes, btw. 😀

hey,.... automation!
¯\_(ツ)_/¯
Excellent, thank you Sixth.

It no longer crashes, but none of these events are changing, making me think it's the way I set up events 19 & 20 at fault now.

Spoiler: Image
Code_13.png


See anything wrong here? I don't. >_>
Oh, and $game_map.rotation is from a commissioned script. I'll post it, because there's no link, because only two people in the world have it.
Spoiler: Script no yell at me
Code:
module HMRS

    module CONFIG
        
        Z_DISTANCE = 100
        BOTTOM_LAYER_Z = 1
        ROTATION_TINT = true
        DEFAULT_ROTATION_TINT_COLOR = 0
        
    end
 
    LAYERS_PATH = "Graphics/Layers/"
    FNAME = "map%03d_%d_%d.png"
    FNAME_NO_ROTATION = "map%03d_%d.png"
    RDIR = [
        {2 => 2, 4 => 4, 6 => 6, 8 => 8, 1 => 1, 3 => 3, 7 => 7, 9 => 9},
        {2 => 6, 4 => 2, 6 => 8, 8 => 4, 1 => 7, 3 => 1, 7 => 9, 9 => 3},
        {2 => 8, 4 => 6, 6 => 4, 8 => 2, 1 => 9, 3 => 7, 7 => 3, 9 => 1},
        {2 => 4, 4 => 8, 6 => 2, 8 => 6, 1 => 3, 3 => 9, 7 => 1, 9 => 7},
    ]
    CRTABLE = [
        {2 => 2, 4 => 4, 6 => 6, 8 => 8, 1 => 1, 3 => 3, 7 => 7, 9 => 9},
        {2 => 4, 4 => 8, 6 => 2, 8 => 6, 1 => 3, 3 => 9, 7 => 1, 9 => 7},
        {2 => 8, 4 => 6, 6 => 4, 8 => 2, 1 => 9, 3 => 7, 7 => 3, 9 => 1},
        {2 => 6, 4 => 2, 6 => 8, 8 => 4, 1 => 7, 3 => 1, 7 => 9, 9 => 3},
    ]
    COMMENT_LINE = "<HMRS invisible>"
 
end

class Game_Map
    
    attr_accessor :rotation
    attr_reader :hmrs_rcx
    attr_reader :hmrs_rcy
    attr_reader :hmrs_bottom_z
    
    alias hmrs_setup_old setup
    def setup(map_id)
        hmrs_setup_old(map_id)
        @rotation = 0
        set_bottom_layer_z(HMRS::CONFIG::BOTTOM_LAYER_Z)
        get_origin_coordinates
    end
    
    def get_origin_coordinates
        @hmrs_rcx = self.width / 2
        @hmrs_rcy = self.height / 2
    end
    
    def rotated?
        return (rotation > 0)
    end
    
    def set_bottom_layer_z(value)
        @hmrs_bottom_z = value
    end
 
end

class Game_CharacterBase
    
    attr_reader :rotation
    
    alias hmrs_initialize_old    initialize
    def initialize
        @rotation = 0
        hmrs_initialize_old
    end
    
    def make_invisible
        @opacity = 0
        @through = true
    end
    
    def make_visible
        @opacity = 255
        @through = false
    end
    
    def rot_visible?(rstr)
        flag_is_visible = true
        if rstr.include?("HMRS invisible ")
            cll = HMRS::COMMENT_LINE.length
            rm_num = (rstr.length - cll)/2
            rm_index = 0
            while (rm_index < rm_num)
                if $game_map.rotation == rstr[cll + rm_index*2].to_i
                    flag_is_visible = false
                    break
                end
            rm_index += 1
            end
        end
        return flag_is_visible
    end
    
    def calculate_collision_coordinates(old_x, old_y)
        x_new = old_x
        y_new = old_y
        if ($game_map.rotation > 0)
            x1 = old_x - $game_map.hmrs_rcx
            y1 = old_y - $game_map.hmrs_rcy
            case $game_map.rotation
            when 1
                x_new = y1
                y_new = -x1
            when 2
                x_new = -x1
                y_new = -y1
            when 3
                x_new = -y1
                y_new = x1
            end
            x_new += $game_map.hmrs_rcx
            y_new += $game_map.hmrs_rcy
        end
        return [x_new, y_new]
    end
 
    def calculate_new_coordinates(old_x, old_y, rotation)
        x_new = old_x
        y_new = old_y
        if (rotation > 0)
            x1 = old_x - $game_map.hmrs_rcx
            y1 = old_y - $game_map.hmrs_rcy
            case rotation
            when 1
                x_new = -y1
                y_new = x1
            when 2
                x_new = -x1
                y_new = -y1
            when 3
                x_new = y1
                y_new = -x1
            end
            x_new += $game_map.hmrs_rcx
            y_new += $game_map.hmrs_rcy
        end
        return [x_new, y_new]
    end
    
    def rotate_position
        rotation_number = $game_map.rotation - self.rotation
        if rotation_number < 0
            rotation_number += 4
        end
        new_xy = calculate_new_coordinates(self.x, self.y, rotation_number)
        moveto(new_xy[0], new_xy[1])
        get_rotated_direction
        @rotation = $game_map.rotation
    end
    
    def get_rotated_direction
        r = $game_map.rotation - @rotation
        new_direction = HMRS::CRTABLE[r][self.direction]
        @diagonal = HMRS::RDIR[r][self.diagonal]
        set_direction(new_direction)
    end
    
    def passable?(x, y, d)
        if $game_map.free_movement_enabled?
            rd = HMRS::RDIR[$game_map.rotation][d]
            rd.nil? ? rd = d : nil
            horz = (d - 1) % 3 - 1
            rhorz = (rd - 1) % 3 - 1
            vert = 1 - ((d - 1) / 3)
            rvert = 1 - ((rd - 1) / 3)
            pixelstep = CXJ::FREE_MOVEMENT::PIXELS_PER_STEP / 32.0
            extra_x = (($game_map.rotation%2 == 0) ? rhorz : rvert)
            extra_y = (($game_map.rotation%2 == 0) ? rvert : rhorz)
            if $game_map.rotation == 1
                extra_x = -extra_x
            elsif $game_map.rotation == 2
                extra_x = -extra_x
                extra_y = -extra_y
            elsif $game_map.rotation == 3
                extra_y = -extra_y
            end
            x2 = $game_map.round_x(x + horz * pixelstep)
            y2 = $game_map.round_y(y + vert * pixelstep)
            rx2 = $game_map.round_x(x + extra_x * pixelstep)
            ry2 = $game_map.round_y(y + extra_y * pixelstep)
            collision_map_xy = calculate_collision_coordinates(x, y)
            collision_map_x2y2 = calculate_collision_coordinates(rx2, ry2)
            rx = collision_map_xy[0]
            ry = collision_map_xy[1]
            rx2 = collision_map_x2y2[0]
            ry2 = collision_map_x2y2[1]
            return false unless $game_map.valid_rect?(x2, y2, collision_rect)
            return true if @through || debug_through?
            if $game_map.collision_map_enabled?
                return false unless map_check_passage_collision_maps(rx, ry, rd, collision_rect)
                return false unless map_check_passage_collision_maps(rx2, ry2, reverse_dir(rd), collision_rect)
            else
                return false unless map_passable_rect?(rx, ry, rd, collision_rect)
                return false unless map_passable_rect?(rx2, ry2, reverse_dir(rd), collision_rect)
            end
            return false if collide_with_characters?(x2, y2)
            return true
        else
            return game_characterbase_passable_cxj_fm?(x, y, d)
        end
    end
    
end

class Game_Interpreter
 
    def rotate_map(id, lid_min, lid_max, rotations = 1)
        if HMRS::CONFIG::ROTATION_TINT
            case HMRS::CONFIG::DEFAULT_ROTATION_TINT_COLOR
            when 0
                tint_black(60)
            when 1
                tint_white(60)
            else
                tint_white(60)
            end
        end
        rotations.times { increase_rotation_variable }
        $game_map.events.each do |event|
            event[1].rotate_position
            if (event[1].list[0].code == 108)
                hmrs_rstr = event[1].list[0]
                hmrs_rstr.parameters.each do |strp|
                    event[1].rot_visible?(strp) ? event[1].make_visible : event[1].make_invisible
                end
            end
        end
        $game_player.rotate_position
        hmrs_setup_map_layers(lid_min, lid_max)
        refresh_layers
        tint_normal(60) if HMRS::CONFIG::ROTATION_TINT
    end
    
    def hmrs_setup_map_layers(lid_min, lid_max)
        id = $game_map.map_id
        for i in lid_min..lid_max
            path_name = "#{HMRS::LAYERS_PATH}"
            fname = sprintf(HMRS::FNAME, id, i, $game_map.rotation)
            unless File.exists?("#{path_name}#{fname}")
                fname = sprintf(HMRS::FNAME_NO_ROTATION, id, i)
            end
            bz = $game_map.hmrs_bottom_z
            z = bz + HMRS::CONFIG::Z_DISTANCE * (i - 1)
            z = 0 if z < 0
            layer($game_map.map_id, i, [fname,0,0,255,z,0,0,0])
        end
        refresh_layers
    end
 
    def increase_rotation_variable
        if [0, 1, 2].include?($game_map.rotation)
            $game_map.rotation += 1
        else
            $game_map.rotation = 0
        end
    end
    
    def tint_screen(tone, duration)
        screen.start_tone_change(tone, duration)
        unless (duration == 0)
            duration.times { Fiber.yield }
        end
    end

    def tint_black(duration = 0)
        black_tone = Tone.new(-255, -255, -255)
        tint_screen(black_tone, duration)
    end
    
    def tint_normal(duration = 0)
        normal_tone = Tone.new
        tint_screen(normal_tone, duration)
    end
    
    def tint_white(duration = 0)
        white_tone = Tone.new(255, 255, 255)
        tint_screen(white_tone, duration)
    end
    
    def set_map_bottom_layer_z(value)
        $game_map.set_bottom_layer_z(value)
    end
    
    def hmrs_transfer(map, x, y, d, lid_min, lid_max, fade = "black", r = nil)
        if fade == "black"
            tint_black(60)
        elsif fade == "white"
            tint_white(60)
        end
        Graphics.freeze
        $game_temp.fade_type = 2
        r.nil? ? r2 = $game_map.rotation : r2 = r
        $game_player.reserve_transfer(map, x, y, d)
        Fiber.yield while $game_player.transfer?
        rotate_map(map, lid_min, lid_max, r2)
        if (r.nil? || (r == 0)) && ($game_map.rotation != 0)
            player_xy_new = $game_player.calculate_new_coordinates(x, y, $game_map.rotation)
            $game_player.moveto(player_xy_new[0], player_xy_new[1])
        end
        tint_normal
        10.times { Fiber.yield }
        Graphics.transition(60)
    end
 
end
I didn't check your rotation script, but I am pretty sure that if $game_map.rotation is 0, it can't be 2 too at the same time, and when it's 1, it can't be 3 too at the same time either, meaning that those things in your conditional branches will never actually run.

You also copy/pasted the same thing in that self-switch condition part twice for some reason, but that could be intentional, although the eventing format is rather weird if it is (it could be done in a much shorter way).
I goofed, made this at 4 in the morning a couple days back. It's supposed to check if it's 0, if not, then 1, and so on. 0 and 2 are grouped because they share collisions; it's the same for 1 and 3. For each of those, it checks if self-switch A is on, as this effects the graphic. I'll fix it, then edit this post.

Edit: I just needed to move the Conditional Branches. All should be fine now, but it still doesn't function. I added a test switch outside of the conditional branches to confirm this.

Code_14.png

I thought this was a pretty concise event. You'd have a stroke if you saw some of my common events. I have one that requires 6 separate common events to work.

Edit 2: I can't see anything wrong with the events anymore, so I took another look at the script call. Sixth gave two methods of fixing the script: one was by changing
Code:
$game_map.events.select
to
Code:
$game_map.events.values.select
. The other was by adding 'key,' to |ev|, making it |key,ev|. I've tried both methods now, with the same results.

Code:
$game_map.events.select{|key,ev|
  ev.name =~ /"Dummy"\s(\d+)/i ? $1.between?(0,99) : false}.each {|key,ev|
  ev.force_move_route($game_map.events[19].move_route)}
Code:
$game_map.events.values.select{|ev|
  ev.name =~ /"Door"\s(\d+)/i ? $1.between?(0,99) : false}.each {|ev|
  ev.force_move_route($game_map.events[19].move_route)}

Is there anything still wrong in this code?
Bump.
Bump. <3
Where do you use that script call? If you run it after that event from the screenshot, that won't work.
You made that event wait for the move route to finish before going to the next command on the list, which means that the move route will most probably be an empty move route by the time the event process reaches your script call.

But that's not the only issue with that script call.
The @move_route instance variable is not a public one, so unless you allow access to it, trying to use it outside of the host object will result in a crash.
And you did not crash, at least you didn't mention any crashes, which means that the selection for the events did not return any match.
The conditions to select an event from that script call is that the event must be named something like:
Code:
"Door" 10
"dummy" 12
Yes, with the quotes and with the space there, without them, they won't be selected. And the number must be between 0 and 99.

So, instead of that script call, try this one:
Spoiler
Code:
mr = RPG::MoveRoute.new
mr.repeat = false
mr.wait = true
mr.list = []
mr.list.push( RPG::MoveCommand.new(36, []) )
mr.list.push( RPG::MoveCommand.new )

evs = $game_map.events.values.select{|ev| ev.name =~ /door_(.*)/i ? true : false }
evs.each {|ev| ev.force_move_route(mr) }
Build your move route how you want, I think, you already know how that works.
With this script call, the events must be named something like:
Code:
Door_Left
door_12
door_tavern
And so on... So, it's a more user friendly regex, you only have to start the name with the door_ part (case insensitive), the rest can be anything you want.
In case you want to select events with different name, just replace that door_ part in the regex to whatever you want it to be.
evs = $game_map.events.values.select{|ev| ev.name =~ /door_(.*)/i ? true : false } evs.each {|ev| ev.force_move_route(mr)

Code:
/door_(.*)/i
if you're not calling the back reference, you can remove the regular expression altogether.
string.include?(substr) should do the trick, if you're just scanning for "door_"

it all depends on whether the bulk of event names is sorted somehow.
I'm using the script call in a common event, two times. Remember the rotation event I was sorting out a while back? This goes with that, and deals with events that need to have Direction Fix ON, but still need to be rotated. There's this script call, turning off Direction Fix for these events (right now, just doors, but will later be any events with Direction Fix ON). Next is the rotation script call, followed by this script call again, turning Direction Fix back on for these events.

I do know how to build move routes now, thanks to your instructions; I still don't know how to make a script call from a move route from a script call, though. I almost made a thread about it, but decided against it. With the way the script call is now set up, I'll need to know how to format it, as part of the move route is changing the doors' hit-boxes to the appropriate shape via a script call in the move route, "set_collision_rect('DOORSIDEOPEN')", for example. This bit of script works, due to another script I have, (GaryCXJk's Free Movement); it's the application I'm stuck on.

Event 19 is going to be remade. The vast majority of the script is checking what direction you and the door are facing, to make sure you can't open the door from the side. I've found a script (http://himeworks.com/2013/10/utils-event-trigger-direction/) that will allow me to massively simplify this.

@gstv87 , I don't know what you mean, but I assume you're speaking to @Sixth . If, by "the bulk of event names is sorted", you mean that the events are grouped by name (events 1 - 10 are NPCs, events 11 - 20 are doors, etc.), then no, they aren't. The events are created as needed, so they're a jumbled mess.

Original thread: https://forums.rpgmakerweb.com/threads/checking-event-names-with-a-script-call-vx-ace.89053/