Dynamically set Switch/Variable names

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
Hey all, so one of the things I've seen done a lot when scripting is to offer different customization options linked to a particular switch/variable, for example a custom menu script where you can cycle through different backgrounds by changing variable x where "x" is chosen by the script's user. So here's my question: is there a way to set the name of a switch/variable via script so that the name shows up in RPG Maker itself? Going to the previous example, the user chooses variable 10, and then the script would set the name of variable 10 to be "background changer" (or something like that) so when the user is doing event editing they don't have to refer back to the script window. Now, I know the user could just set the names themselves, but if there's a lot of options it would be easier to set via script so just humor me on that point.

I've already done some digging and here's what I've come up with (note this was in RMXP; may be different in VX/Ace). The "Data/System.rxdata" file contains the strings used for switch/variable names. This file gets loaded into the global variable "$data_system". Referencing "$data_system.switches" returns an array of strings of the switches names. So I called the following in game.

def rename(id, name) $data_system.switches[id] = nameendI checked via the debug menu, and sure enough this will change the name of a switch. But it's not permanent obviously. Starting a new game via quit to title will undo it. But if you change it to the following:

def rename(id, name) $data_system.switches[id] = name save_data($data_system, "Data/System.rxdata")endYou can save whatever changes you've made. I even quit the game entirely and started it up again and found the new name had stuck. However, this still doesn't cause RPG Maker itself to recognize the new names and display them in the editor. So any thoughts? Are the switch/variable names that RPG Maker uses saved elsewhere? Like in the project file? Can this even be done? 
 
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
You don't generally rename $data_... things. If you do, you DEFINITELY wouldn't save it to System.rxdata because it would affect EVERY save game, not just the current one, AND when you loaded it in the editor again.


There is no such thing as $data_switches and $data_variables. They are $data_system.switches and $data_system.variables. You're on the right track, but save it with the player's save file, not into System.rxdata


Or you could just add a couple of lines to Game_System to duplicate $data_system.switches and $data_system.variables as part of the initialize routine, and it'll already be saved to the player's file along with the rest of $game_system. I don't actually think $data_system.switches and $data_system.variables are USED anywhere in the scripts, apart from DEBUG, which your player wouldn't normally have access to, so it would be easy for you to just make your scripts refer to $game_system instead of $data_system when changing and pulling out these values.


In fact, that's the option I'd go with if I wanted to do such a thing. But really, I'd just use a standard array and not mess with switch/variable names at all. You really don't want players to be able to reallocate your switch/variable use. That would break your game.
 
Last edited by a moderator:

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
Whoops. $data_switches is a typo. Meant to put $data_system.switches.

But that's the point - I want the names to load into the editor. I'm trying to make the developer's life easier by writing a script that automatically renames the switches/variables so they can keep track of things. The player will never see what I'm trying to do; this is all for the developer. However, saving the changes to the rxdata file does not cause the new names to appear in the editor.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Why would you do a script so that they have to play the game in order to name variables and switches, when they can simply do it while creating their game?


I'm not sure what you're trying to do, or rather, WHY you're trying to do it. It is not difficult to name a variable or a switch under the existing method.
 

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
Whoops. $data_switches is a typo. Meant to put $data_system.switches.


But that's the point - I want the names to load into the editor. I'm trying to make the developer's life easier by writing a script that automatically renames the switches/variables so they can keep track of things. The player will never see what I'm trying to do; this is all for the developer. However, saving the changes to the rxdata file does not cause the new names to appear in the editor.
The editor doesn't know, and doesn't care, what you do to the data files after the project has been loaded into the editor. If you hit save in the editor, the current state of all the database items in memory is then written to the various data files, it doesn't care about the previous state or even if they have been changed since last save. The exception to this is maps - where they will only export new versions if the version in memory was changed in some way (even if said change was undone) - and they still don't care what the file they are overwriting is or if they have been modified by some external source.


Of course, if you save the project before playtesting, run the script that alters the data files via playtest, close the playtest, close the editor without saving again, and THEN load the project in the editor, everything will appear as you would expect it to. But that isn't much of a convenience method.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
Why would you do a script so that they have to play the game in order to name variables and switches, when they can simply do it while creating their game?
Because if for example Yami's overlay/parallax script could rename the variables it needs for itself on first playtest, we wouldn't get as much bug topics about "why does my parallax map don't work after I talk to my quest event", just because the people using the script forgot to even look at what variables a script needs...
 
Last edited by a moderator:

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,309
Reaction score
531
First Language
indonesian
i think that's too piggy backing. :D . not to mention even you do that they can still mess up by overlapping with other script switches. so i think that's overkill. i think the user is the one who need to read scripts header more carefully instead letting the developer do all the work :D ... it's like having a gun and a gun manual. but the user of the gun didn't read the manual carefully. and didn't unlock the gun. thus the gun cannot be fired. do we blame the gun manufacturor? no... we blame the gun user :D .
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
The editor doesn't know, and doesn't care, what you do to the data files after the project has been loaded into the editor. If you hit save in the editor, the current state of all the database items in memory is then written to the various data files, it doesn't care about the previous state or even if they have been changed since last save. The exception to this is maps - where they will only export new versions if the version in memory was changed in some way (even if said change was undone) - and they still don't care what the file they are overwriting is or if they have been modified by some external source.

Of course, if you save the project before playtesting, run the script that alters the data files via playtest, close the playtest, close the editor without saving again, and THEN load the project in the editor, everything will appear as you would expect it to. But that isn't much of a convenience method.
I was just thinking that might be the case. Gonna go test it...

And it works! Awesome.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
Why would you do a script so that they have to play the game in order to name variables and switches, when they can simply do it while creating their game?


I'm not sure what you're trying to do, or rather, WHY you're trying to do it. It is not difficult to name a variable or a switch under the existing method.
Several scripts require you to run playtest, then close your project and reload it. This is often used to bypass editor limitations, or just to, for example, generate 500 maps without having to do it manually.


If names are important to a dev, then this may make things easier.
 
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
oh - limit breakers and stuff? Yeah.


And I LOVE the idea of Yami's script naming its own variables. If I had a dollar for every "why won't my overlay appear" question that turned out to be failure to set switches, I'd be able to treat my family to takeaway for dinner tonight :)
 

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
In case anyone was wondering, this is why I wanted to do this.
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top