Ruby/RGSSx questions that don't deserve their own thread

Hi, I am looking for an option to get the name of variables and switches during runtime, is their a way?
This will work for displaying the names of switches (Edit and variables) in the order they appear to the console:

Put this snippet in it's own slot below materials and above main.

Edit: Also can show the hierarchy of maps

class Print_Name def S_Name p "Start of Switches" for i in 1...$data_system.switches.size p "#{i} " + "#{$data_system.switches}" end p "End of Switches" p "" end def V_Name p "Start of Variables" for i in 1...$data_system.variables.size p "#{i} " + "#{$data_system.variables}" end p "End of Variables" p "" end#Thanks to a method in Dr.Yami's Patch script and to Another Fen can show the maps Hierarchy def HM_Name p "Beginning of Map Hierarchy"    hash = Hash.new    $data_mapinfos.each { |key, value|    hash[0] = value    p "parent id #{hash[0].parent_id} order #{hash[0].order} name #{hash[0].name}"    } p "End of Map Hierarchy" p ""  endendMake an event with the script command:

Code:
name = Print_Name.newname.S_Namename.V_Namename.HM_Name
Thank you, this is what I was looking for.

First checkmark on my list.
Edited the snippet should be able to do every thing you want.

Edit actually does it by when the map was created (reason I thought otherwise was because I forgot when I made some of my maps) :/ So don't think you can do hierarchy of maps.
$data_mapinfos[map_id].parent_id

should return the ID of a maps parent. It should return 0 when the map is placed at the top level of the hierarchy.
 

To reconstruct the entire structure you could use something like this for example:

hash = Hash.new { |h, k| h[k] = Hash.new }

$data_mapinfos.each_pair do |map_id, data|

  hash[data.parent_id][map_id] = hash[map_id]

end
hash[0]
Thanks Fen found a way to reconstruct the hierarchy based on your information and reedited my post. 🙂

Edit at below: Well my way does show the hierarchy of maps based on parent id and the order they are listed, your way is by far more efficient and looks a lot nicer overall.
And what I would like to get aswell ist hierachy of the maps.
While Another Fen's snippet does generate a hash representing the map hierarchy (and Sarlecc technically provided a way to print map information), I think you'll probably find this more useful than either of the solutions posted if you just want to print an accurate hierarchy of map data to the RGSS console:

module MapTree def self.print_maps $data_mapinfos.sort_by { |(_, map)| map.order }.each do |(id, map)| this_map, i = map, 0 (map = $data_mapinfos[map.parent_id]) && i += 1 until map.parent_id.zero? puts 'Map %03d: ' % id << (' ' * i) << this_map.name end endendTo print the map hierarchy to the RGSS console, simply call MapTree.print_maps inside of a Script Call event command. This will print the hierarchy while the game is running in the same way that it has been constructed in the RPG Maker VX Ace editor.Example output using a test game (using sample maps which were shuffled and arranged into a hierarchy rather randomly):

Code:
Map 003: EmptyMap 007:   Items ShopMap 002:     Historic Ruins Entrance 1Map 004:       Ancient Historic RuinsF3FMap 008:   Magic ShopMap 006:     Armor ShopMap 005: Slum
Note: Honestly, if I were writing this for my own purposes, I would do it entirely differently -- the above code works perfectly fine, but it's not as object oriented as I'd like.
I'm sorry if this is the wrong place to post this. I've upgraded to VX Ace and i am learning the ropes at a decent pace. Most of the projects that I work on

require a script built by Tomoaky for best performance in the actions i try to accomplish. When i made the jump to VX Ace i was very happy and i realized

how much more options i had with it however, I ran into a small problem. Tomoaky has translated a certain amount of his RGSS2 scripts into RGSS3 and

the script i work with has not been translated. On his page he says he will be taking down his page so now i'm not very certain that he will ever translate

my script. With this knowledge I tried to do it my self, in the past i have heavily modded scripts to fit my needs but translating an entire system is beyond

me and i keep getting an error after another when i work on a line. is anyone familiar with the file "act_btl_Ex" that could help me translate the script? and

by helping i mean doing the majority of the work sadly because i keep getting no method errors. The script allows you to have maps that are in a megaman platformer style and gives several options like gravity, Jump hight, direction of weapon fire and gives several options for the enemy also But the most important part is that the platformer maps are only an option meaning that you can also have maps which you can explore a city and forest and if you run into a monster you can start the script to send you into a platformer style map where you'll fight the monster. or you can just use the script for mini games. I'm asking such a daring request because the script doesn't seem to have many problems with RGSS3 and most of the conflict comes because many of the lines in VX Ace have been changed to fit the new troops tab and new options given in the game.
Is there a way to update the save window upon confirmation of a successful save before return scene is completed?
@Master100000, please post in a new thread - custom scripts don't go in the "...questions that don't deserve their own thread" thread. Post in RGSS3 Script Requests with a link to the script asking for someone to do a conversion. If you're worried he takes his site down before it's done, copy it and put it onto pastebin or something and put the link there. Make sure you grab his terms of use before his site is gone.


@palladinthug, you would need a script that will pop up a new window and wait for user to respond when the save is done. That would also be a RGSS3 Script Requests thread. Do a search though, because it sounds vaguely familiar and there might already be one out there.
Is there a way to update the save window upon confirmation of a successful save before return scene is completed?
Try the following (paste above all custom scripts):

class Scene_Save < Scene_File def on_save_success Sound.play_save @savefile_windows.each { |window| window.refresh } endendIf you want it to call return_scene automatically, you could use something like:

Code:
class Scene_Save < Scene_File  def on_save_success    Sound.play_save    @savefile_windows.each { |window| window.refresh }    # Amount of frames to wait before calling return_scene-    Graphics.wait(40)    return_scene  endend
Hi, I have a simple question: via script, how can I get the element of a skill?

I found nothing in the help files and have no clue where to find it in the basic scripts of the RPG maker, but somewhere it have to be stored,

since you can give a skill an element in the database.
Try using the 2nd tab of the help file, and find the articles about RPG::BaseItem or RPG::Skill or maybe RPG::Item, or maybe RPG::BaseItem:😀amage (or something like that) it must be somewhere there. Don't have Ace here so...
Miko is right, you can find it on help file.Go look at RPG::UsableItem:😀amage, there is attribute called element_id, you should can use that.
I think call it like this : skill_object.damage.element_id

 
Yeah, I found it now. I have to say, it is very .. complicated to get this data. you know what I mean? why go around 5 corners to find it! 

But thanks to you two =D
Well, it could be if ur not used to finding things. 🙂 It's still logical though since it's an instance variable of the RPG::BaseItem:😀amage class after all 
If you are not sure how to get the desired data for a database item, here is what you can do:


Make an event. In the event, just make a script call command like this:

p $data_object[id]You can do this in a script in the script editor also.
Examples: p $data_skills[12], p $data_actors[5], p $data_weapons[34], etc.


This will print everything out about an object of your choice.


You will see many "@var_name" texts in the console and their value.


Those are the datas of the object you just printed to the console.


If you enter $data_object[id].var_name, you will get that data returned.


Some of them are "sub-datas", just like the element of the skills, but those can be identified quickly as well. You will see the same "@var_name" displayed, but after the name of it, you will see something like "<RPG:😮bjName...". If you see that, you will first need to enter the first @var_name which was before the <RPG:😮bjName... text and after that, enter the second @var_name inside that RPG:😮ject.


This is how I find specific data for an object. Much quicker than searching for it in the help files which can't even show you the new, custom effects from custom scripts. It also shows the value of each data, so even if I don't know what some data means, I can still assume it if I see their values.


Sorry if I failed to explain this in an understandable way, I kinda suck at explaining these scripting things. 😛
Is there a way to search events that containing specific switch or variable control? I want to check a variable usage through events, so I can spot my mistake faster.
Is there a way to search events that containing specific switch or variable control? I want to check a variable usage through events, so I can spot my mistake faster.
Of course. The following snippet assumes that you know a decent amount about the specific switch or variable operation you are looking for, but also serves as a decent template to be able to find an event with any event command and parameters that you may want to filter.

Code:
module EventFinder  # Returns an array of events on the current map which set the value of the  # switch with the given `id` to the given boolean `value`.  def self.with_switch(id, value)    batch_with_switch(id, id, value)  end    # Returns an array of events on the current map which set the values of the  # switches within the range of `start` to `finish` to the given boolean  # `value`.  #   # **Note:** the given `start` and `finish` values absolutely **must** match  #   what was defined in the event editor.  def self.batch_with_switch(start, finish, value)    # **Note:** we're converting a boolean value into `1` or `0` due to how the    #   editor stores these values internally (the internal values really don't    #   make much sense).    value = value ? 0 : 1    with_command(121, start, finish, value)  end    # Returns an array of events on the current map which perform the given  # `operation` (with the given `operand`) to the variable with the given `id`.  def self.with_variable(id, operand, operation)    batch_with_variable(id, id, operand, operation)  end    # Returns an array of events on the current map which perform the given  # `operation` (with the given `operand`) to the variables within the range of  # the given `start` and `finish` values.  #   # **Note:** the given `start` and `finish` values absolutely **must** match  #   what was defined in the event editor.  def self.batch_with_variable(start, finish, operand, operation)    # **Note:** we're converting descriptive symbol names into integers here    #   due to how the editor internally stores operands and operations.    operand   = [:const, :var, :rand, :game, :script].index(operand)    operation = [:set, :add, :sub, :mul, :div, :mod].index(operation)    with_command(122, start, finish, operand, operation)  end    # Returns an array of events with event commands matching the given command  # code and parameter list.  #   # **Note:** the parameter list is built as-needed; only include as many  #   parameters as you need to filter events.  def self.with_command(code, *params)    return [] unless $game_map    $game_map.events.values.select do |event|      event.list.any? do |cmd|        cmd.code == code && cmd.parameters[0...params.size] == params      end    end  endend
Most of this seems self-explanatory to me, but let me briefly explain how to use this: basically, unless you're using a REPL, you'll probably be calling this from an event using a script call event command. Assuming that's what you're wanting to do, I'll create a few examples:

Code:
# **Note:** All of these examples print to the console with `p` in order to accurately# report the array of found events.# Find all events on the current map setting switch ID `1` to `true`.p EventFinder.with_switch(1, true)# Find all events setting a batch of switches (from `1` to `5`) to `false`.p EventFinder.batch_with_switch(1, 5, false)# Find all events setting variable ID `5` to a constant value.p EventFinder.with_variable(5, :const, :set)# Find all events adding a random amount to variable ID `1`.p EventFinder.with_variable(1, :rand, :add)
Let me know if you need more help understanding how this works (or if you need some other way of filtering events).
@Solistra: Hm, yes, this is what I am looking for. Except one, feature to check through all map id, but I think I can do it with common event. Thank you very much, Solistra. 
@sokita, look for my Extract Event Contents script.

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/