Simple way to reorganize variables and switches?

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
31
Reaction score
3
First Language
English
Primarily Uses
RMMV
Hey everyone! I have a simple question, I've been working on a game for a while now and as expected, I have been using variables and switches.

When I had started the project I had pre-sorted them so that for example, 1-100 would be plot related, 150-200 would be for a certain mini game, 200-220 was for player inventory stats and such.

The planning ahead has worked pretty well with keeping things organized, but there have been times where I wish I could add some more variables to the "mini game section", so my question is:

Is there any way to "shift" or reorganize variables? Could I change all references to variable 001, to variable 002 in events or something?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,036
Reaction score
2,289
First Language
English
Primarily Uses
RMMV
Weeeeeeell....kinda-sorta, but not really.

What you can do is open all of your json files in like Notepad++ or something and replace all occurrences of $gameVariables.value(x) with $gameVariables.value(y). And you could also do a global replace on the event command for manipulating variables to do the same replacement. But this won't change the references in plugin parameters which use that variable for something, or anywhere you've just referenced it as an ID.
 

jjraymonds

Veteran
Veteran
Joined
Feb 1, 2020
Messages
31
Reaction score
3
First Language
English
Primarily Uses
RMMV
Weeeeeeell....kinda-sorta, but not really.

What you can do is open all of your json files in like Notepad++ or something and replace all occurrences of $gameVariables.value(x) with $gameVariables.value(y). And you could also do a global replace on the event command for manipulating variables to do the same replacement. But this won't change the references in plugin parameters which use that variable for something, or anywhere you've just referenced it as an ID.
I figured it wouldn't be the "cleanest" solution but I'm willing to put in the work to keep things efficient during the rest of my dev time- just to clarify because I've never gone into my project's JSON files yet:

Each map is its own JSON file right?

If I do a find and replace all for "$gameVariables.value(x) with $gameVariables.value(y)" that would cover instances of modifying variables (like addition, multiplication etc.) right? It would also fix any conditional branches?

Is there anyway to both, do the same variable reference updates in common events, do they have their own JSON files? also, is it possible to reorganize common events this way as well? After all, they are just listed with numbers too right?

Plug-in references makes total sense- I don't think I'll mind going through that stuff by hand if I can do the rest "quickly"

Thanks for helping out by the way!!!!!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,036
Reaction score
2,289
First Language
English
Primarily Uses
RMMV
No, that one ($gameVariables.setValue) would only replace it in script calls where you referenced variables directly in code. And yeah, every map has its own JSON file containing the event data.

For the event command, you want to replace these:

JavaScript:
{"code":122,"indent":0,"parameters":[9,9,2,0,5]}

Code 122 is the "control variables" command. The parameters consist of the starting variable ID, the end variable ID, the ID of the operation (0 is "set" up to 5, "mod"), the ID of the operand and the value of the operand. Some operands have additional values (like "random" adds an extra value so that it has a min and a max)

The important part is replacing the start and end ID with the new value.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,149
Reaction score
14,650
First Language
English
Primarily Uses
RMMV
Unfortunately, I don't think you could do that without a plugin @Trihan - in addition to Control Variables (where you have the variable id/range to change, but also the option of changing it to what's in another variable), variables are also used in event page conditions, Conditional Branch, all of the Change Actor group (HP, MP, Equips, States, etc), Transfer Player, Set Event Location, Set Vehicle Location, Get Location Info, Show / Move Picture (I think), possibly all the Change Enemy commands (where you can increase/decrease by a variable) and probably half a dozen others. (maybe this is what you meant by "anywhere you've just referenced it as an id").
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,036
Reaction score
2,289
First Language
English
Primarily Uses
RMMV
And those are all done via the same sort of structure, Shaz. As long as you know the pattern for all of the event commands that might use variables, you can do enough replaces to pull it off. It's still a lot of work, but possible if you're okay sorting the plugin parameter parts manually.

Event conditions:

JavaScript:
{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":14,"variableValid":true,"variableValue":5}
You'd have to use a regex pattern match for this one for the other numbers, and then replace variableId with the new one.

Conditional branch:

JavaScript:
{"code":111,"indent":0,"parameters":[1,9,0,4,4]}

You're looking for any code 111 with a first parameter of 1 (variable); the second parameter is the ID. You might also have to do a search for any with a third parameter of 1 (variable operand) to make sure you replace any that have the replaced ID there too.

The change actor ones are codes 311 up to 318. There are a few parameter layout differences for the different commands so you'd have a few to do there.

It's still a lot of work, but still doable for the event command side of things.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,149
Reaction score
14,650
First Language
English
Primarily Uses
RMMV
Some of those event commands sometimes use variables though, so you'd have to include a test there to say "if parameter 2 is 1, then parameter 3 is a variable id and might need to change, otherwise it's a constant and should be left alone".

Yeah, it might be possible with some crafty regexp replacements. But if you have 500 variables defined and you want to insert an extra few before #100, that means you'd have to run your manual replacer up to 400 times.

I'd rather have a slightly messy database, especially as nobody is ever going to see it when they play :D The order of items, weapons, armors, etc is a much more visible thing.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,036
Reaction score
2,289
First Language
English
Primarily Uses
RMMV
This topic's actually whet my appetite a bit, I might write a tutorial for doing this and cover every possible match/regex you'd need for it.

You're right though: the payoff in most cases wouldn't be worth the expenditure of effort. This would mainly be if you're *really*, *really* keen on having your data that organised.
 

ZenVirZan

Villager
Member
Joined
May 13, 2020
Messages
19
Reaction score
26
First Language
English
Primarily Uses
RMXP
I've written a process for RMXP that does this (along with all database items as well), which is a bit more difficult as files are Marshalled instead of human-readable like MV's json. I'll be releasing the RMXP version in the next few days.

I was planning to add MV support, but it's a Ruby script requiring Ruby to be installed on the user's machine due to XP's quirks, which isn't a good prerequisite for MV users. XP users on the other hand can deal with it :cool:

Maybe I'll release it as its own thing, separately. We'll see. The code only took like a day or two to write, its just grindy, not difficult. I don't use MV so the motivation isn't quite there for me yet, but keep an eye out for it. Considering the notes system exists in MV, it'd have a better chance of compatibility with scripts as you can track items using an identifier in there (unlike XP :frown:)
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

2dfloor.png
What a fun tileset I've got here so far!
Minecraft Tiles, Maid Day, Custom Menu, Retry at GameOver, Save in Appdata | RPG Maker News #36

side view special bust.png
Reworking the art for the 'special busts' in important game dialogue. Potentially replacing the more 'dead-on' look of the original:
original.png
Me: Imma work on my game! Let's get some progress done
Me, five minutes later smoking a cigarette: *screams into the void*
Just got back from work... I got to recommend a dish I liked to a group of senior ladies, and they said they'd order it for dessert! What was it? CHURROS! It's one of my favorite desserts at my workplace.
What's your favorite dessert? I'll eat any pastry with cinnamon and sugar, but especially churros. And then there's chocolate... omg, so good!

Forum statistics

Threads
111,261
Messages
1,059,632
Members
144,541
Latest member
fmoviesfco7
Top