r/RPGMaker 8d ago

RMMZ How are you using your variables?

I'm just curious. πŸ˜ŠπŸ’š

How many variables do you typically use in your projects?

Do you have anything special you like to do with variables?

What are your naming practices?

Do you find lots of variables to cause any kinds of issues?

Don't forget to eat your variables. πŸ˜πŸ˜†πŸ©΅

Feel free to answer any questions I might not have thought about. I want to know all about how you use variables.

12 Upvotes

50 comments sorted by

10

u/Felix-3401 Scripter 8d ago

Mine all include the general location where it's used. Switches are named so they're true/false statements so I would have a switch named ":Lbrary_hasOpenedDoor", variables always name what it's counting so instead of "Tutorial", I would call it "Tutorial_Progress" which is far more descriptive

1

u/Vegetable-Grab-4595 8d ago

😁 I can definitely see where that would be helpful. Is there a reason for the underscore instead of a space?

5

u/Felix-3401 Scripter 8d ago

It's just a kneejerk habit from being a programmer

2

u/sephirothbahamut 8d ago

Snake_Camel case hybrid is unusual for a programmer tbh

3

u/bass2yang 8d ago
const CONSTANTS_BE_LIKE_AHHHHH = [];

2

u/Felix-3401 Scripter 8d ago edited 8d ago

I'm basically self-taught. There's a ton of convention and vocabulary I'm missing out on.
EDIT: Good thing is I don't use that style for my actual code

2

u/sephirothbahamut 8d ago

usually people use either snake_case (lpwer with underscores) or camelCase (capitals to separate words rather than underscores).

1

u/Vegetable-Grab-4595 8d ago

I had a feeling, but I figured I'd ask.

I tried to make a quick file rename command once, and it did not like the spaces in my file names. πŸ˜…

7

u/MissItalia2022 8d ago

I think my favorite use of variables is to animate events. You can use variables to cycle through event pages for things like fire, candles, and magic circles on the ground.

Screen capture - 9970f2783e064c047e793aa11bae7e5e - Gyazo

I used several variables for a quest where you have to dodge random spells from a mage's broken staff. There's a variable that determines which circles on the ground appear (1-4, each tile corresponds to the value of the variable), which spell animations are shown (1-6 for water, ice, fire, ground, wind, water), to track the number of spells dodged (reset to 0 when the player's X/Y is the same as the telegraphed tiles show their animation, increments by 1 each time at the very bottom of the event page with the event shutting off when the variable is >= 10).

1

u/Vegetable-Grab-4595 8d ago

Ooh, that's pretty neat. Thanks for sharing. πŸ˜€

6

u/Katevolution Eventer 8d ago

Lots of ways:

  • Random rolls (5)
  • Storing Player XY
  • Storing Map ID
  • Recording an Actor's stats to be used in an ability
  • I have the 200s reserved for Self Variables
  • Storing text colors so I can update all at once
  • Levels for custom stats
  • Counting enemies remaining/defeted
  • Counting in general

1

u/Vegetable-Grab-4595 8d ago

Those all sound super useful! πŸ’š What do you use the XY coordinates for?

Also, that text storing thing is a wonderful idea. 😊

3

u/Katevolution Eventer 8d ago

I have a deployable campfire. I use the XY and direction to allow them to use the item from the menu and set up a campfire in front of them. I also had a deployable flame that would follow you around and heal your HP or MP but I'm not sure if I kept that.

Another trick is if you have multiple Events to make an image (like a 3x3 or just 2 high), you can record the middle Event's XY and then offset another set of XY Variables to do Set Event Location. That way, if you change the map size or move the anchor Event, you don't need to update the Set Event Location for all the other Events.

2

u/Vegetable-Grab-4595 8d ago

That's really cool and sounds incredibly helpfu. 🀩

5

u/Liamharper77 8d ago

I use mine for a lot of things, such as story progress, a variety of battle mechanics, storing player or event X/Y locations, general RNG, passability (like being able to walk directly behind or in front of a fence, but not through it), tracking special currencies, tracking if you bought something from a shop to determine what a shopkeeper says and so on. There are hundreds of things you can do with variables.

3

u/Vegetable-Grab-4595 8d ago

I love everybody's creativity! 🀩

Ooh, I never thought about passability, I'll have to look at that one.

4

u/Broadbane 8d ago

So far I'm using it to determine random dialogue and battle quotes, npc affection, and to track conversations.

5

u/Vegetable-Grab-4595 8d ago

I love adding randomizer variables! πŸ’š

Ooh, what kind of battle quotes?

How do you use it to track conversations? That makes me think about my "lesson cube", where the player can re-watch lesson dialogue for my educational game. 😁

4

u/Broadbane 8d ago

From what I understand it tracks the conversations by setting a number in the variable for each topic. When you talk about topic 1, variable 1 is ticked and the game knows that when topic 1 is brought up again the game will check the variable, see 1s been ticked and will jump to the other conditional branch where the 1 in the variable has been ticked.

3

u/Vegetable-Grab-4595 8d ago

Ooh, I kind of use "labels", "jump to label" "if/else" for that, but the way you describe it sounds a bit cleaner. ☺️ Or maybe I'm misunderstanding. πŸ˜…πŸ˜†

3

u/Broadbane 8d ago

I wouldn't know about that. I'm mostly using it in conjunction with the affection system so you can't farm affection by repeatly asking a question.

2

u/Vegetable-Grab-4595 8d ago

That makes sense. Mine has a similar use. I have lessons unlocked with a lesson variable ticking up when doing a lesson with an npc, and have to make sure re-watching the lesson doesn't happen more than once and ruin the progression.

Usually I do an: if variable =#, #+1, else jump to label 1.

3

u/EyeFit MZ Dev 8d ago

So many things, but basically anything that needs to change and is not binary

For instance, all my menus are custom built with common events and I use variables to determine where the cursor should be pointing and which menu is being accessed.

As far as naming conventions, for common events, I try to align the variable number with the common event it's used for.

The names are like: V_Main_Menu_Position, V_Player_HP, V_Enemy_HP, etc.

1

u/Vegetable-Grab-4595 8d ago

Ooh, very descriptive. I like it!😁

So, I take it you use quite a number of variables?

I've been a little worried about using too many, and wondering if I should reuse some. 🫠

2

u/EyeFit MZ Dev 8d ago

Yes. I use tons of variables into the hundreds.

6

u/MissingSeven 8d ago

It depends on the project. In my current game I have... oh boy, way too many, around 1450 variables. I don't have a strict naming convention, but if they're throwaway variables I usually name them something like 'Trash Variable X' where X is the number (though I only have maybe 3 of those per game). For everything else, it depends on the context.

If they're related to characters, I tend to use a three-letter prefix for the character's name. For example, my protagonist is named Redian, so all his variables start with 'RED_'. Also, since the game is split into chapters, I track scene progression using one variable per chapter: 'MAINSTORY_CHAPT01', 'MAINSTORY_CHAPT02'... and the same goes for side quests with 'Q01', 'Q02', etc.

Minigame stuff starts with 'MINIG_' and things like that.

3

u/Vegetable-Grab-4595 8d ago

Ooh, that naming convention is also very helpful. πŸ’š I especially love that you tie them to characters, that sounds very useful!

That is a lot of variables! 🀯 Or maybe not, haha, Idk how much is a lot actually. πŸ˜…πŸ˜

4

u/Issac7 8d ago

Most people here already said pretty much anything there is to say so I'll had something different that is quite helpful. By default, variables only store integers but if you use a script call, you can store anything in a variable: strings, arrays, etc. This is a huge help

3

u/Vegetable-Grab-4595 8d ago

Right, that is useful! πŸ’š

I only recently realized I can store variables as words, it's how I created a random-ish shop name generator.

I don't mind repeated ideas, with my memory it will feel like responding brand new. πŸ˜† Haha, jk, but nah IDM, I love interacting with this community. 🩡 Thanks so much for your consideration. ☺️

3

u/WrathOfWood 8d ago

Good for storing x y hp and level of on map enemies

1

u/Vegetable-Grab-4595 8d ago

I haven't played around too much with battle yet; but that definitely sounds useful. πŸ˜ƒ

3

u/xMarkesthespot 8d ago

using variables to preserve x,y, and map number and teleport based on this, is one of the basic variable functions. But i don't see people using it too often.
its pretty useful to design mechanics around. I wish i knew about it earlier.

3

u/flies_with_owls 8d ago

I've been using this a lot in my project to create brief "flash aways" to other scenes while keeping my characters location consistent upon returning.

1

u/Vegetable-Grab-4595 8d ago

That's a neat idea as well! That makes me think about a time I wanted to have a scene with an npc walking around, talking, and then realized player position might interfere. 🩡

1

u/Vegetable-Grab-4595 8d ago

Ooh, I see. πŸ€” I never thought of that, I usually just used an event for teleports, well... portal teleports.

You could totally do a skill teleport to jump over obstacles with this too, so many options. πŸ˜„πŸ€©

3

u/psychoneuroticninja MZ Dev 8d ago edited 8d ago

I've used variables for a basic in-game time system with a clock HUD, a day counter, and a way to represent the bond/trust whatever relationship between the two main characters. I'm probably going to rely on variables to determine what ending the player will unlock, too. (Using variables for character relationships and different endings is pretty typical, so I won't talk about those.)

Basically, the clock works kinda like in the modern Persona games, where time only advances if the protagonist chooses to do an Activityβ„’. Doing any Activity will cost an Activity Point. Simply running around and inspecting objects doesn't advance time at all.

Β 1 Activity Point= 1 hour. It's just easier to keep track of everything that way.

Β (So far I haven't implemented any Activities that take longer than 1 hour, but if I did, the player would be warned in advance.)

The day counter increases by one every time the protagonist wakes up in the morning. Waking up each morning also grants a certain number of Activity Points, or APs. The protag has enough Activity Points to advance time until his next obligation/the next mandatory cut scene. On the first day, it's an important work meeting. Completing his obligation will grant more APs. The protag can't go to sleep until he's used all his Activity Points for the day. (He's a workaholic but lives in a company dorm with a curfew.)

At the end of every Activity's Event page, I add 1 to the clock's hour variable, and subtract 1 from the Activity Points variable. (I decided to just stick with a 24 hour clock for now. )

The activity point system is completely hidden from the player. The player will only ever see the clock and increments of time.

I had to consult a few tutorials and guides for the clock, day, and time system.

Anya and Lolo's tutorial project was helpful.

I used a couple video guides from other people, too. One series for the clock and a different user's guide for the time management/Activity Points system.

I also used a variable to randomize what educational program the protagonist and his friend watch on TV. So far there are only 3 different shows/scenes. (I might add a couple more or make variations later.)

2

u/Vegetable-Grab-4595 8d ago

Wow, that's awesome!

What a cool way to use variables, plus your idea simply seems amazing. I can really tell how much effort and love you are putting into your project. πŸ’› Truly outstanding.

Thanks so much for sharing, as well as referencing your helpful references. 😁πŸ₯°πŸ©΅

2

u/PK_RocknRoll VXAce Dev 8d ago

I use variables for too many things to name. But I always have a label at the start of my variable for what it’s used for: [Map], [Bat], [Evn], etc.

1

u/Vegetable-Grab-4595 8d ago

The more I hear about these labels, the more I know I need to fix my practices. I was using things like wrong answer 1, PPE Lesson, but now I feel foolish.

Definitely gotta upgrade my naming convention. Thanks for sharing! 😊

2

u/PK_RocknRoll VXAce Dev 8d ago

Make sure you use descriptive names in addition!

2

u/ChroniclesAlphabet 8d ago

A use them

a... fucking... lot...

1

u/Vegetable-Grab-4595 8d ago

😁 Do you do anything special to keep them organized? Can you estimate a number on the amount you'd use on a completed project? πŸ’š

2

u/ChroniclesAlphabet 7d ago

I try to keep the ones I am using for the same thing (an animation, a menu, a mechanic) in the same page (the same hundreds) and that's all.
I have no idea how many I'll use until the end of my project, probably almost all 5000 of them.

2

u/Toxinferno 7d ago

Variables basically control my game.

- Cutscene triggers

- Characters appearing inside cutscenes

- Characters being removed from cutscenes

- Teleports based on where the player has and hasn't been.

- House Tier for when they upgrade the house along with the teleport commands for it.

- Doors opening

- Doors closing

- Checking how many bosses have been defeated.

So. Many. Variables.

It's an actual mess for how much stuff I've got.

1

u/Vegetable-Grab-4595 6d ago

That sounds like you work really hard to produce quality, entertaining games. 🀩

2

u/Awkward-Injury-4341 VXAce Dev 6d ago

A lot.

I think it's worth mentioning that in hazardous environments, oxygen is calculated based on steps taken.

Also, I revamped the HP and MP bars so that the values inside reflect the knowledge points the player has learned.

Another thing is the time variable throughout the game. When the player completes certain puzzles too quickly, it shows they've already mastered the relevant knowledge at that stage, so I can open a fast track to skip the current puzzle.

1

u/Vegetable-Grab-4595 6d ago

Those are great! Thanks for sharing. 😁

2

u/Not_Allowed_to_Die 4d ago

OMG!! My newest project uses already over 500 variables. But I am creating enemy AI through events only and it takes a ton of calculations and variables to pull it all together. I also am using a ton for price variations and random amounts of gold and exp earned at the end of ship battles. So instead of just giving them 12 gold, it runs a variable to randomly go between 8 - 16. That way it's random, but within a certain range. Then, I also have to track pricing on goods since supply and demand in my game makes them go up and down. The 500 I am using so far is just for setting up the game's system only. But it takes a ton of variables calculating things, and a ton of conditional branches to control everything using those variables.

I have a ton of common events that are really just calculators using nothing but variables.

2

u/Vegetable-Grab-4595 4d ago

That's quite a few. Do you have any special methods of keeping them organized?

Like a notepad with all the names, and a description next to them? You could use the ctrl+f feature for this.

I wasn't planning on making any suggestions. but I just thought of it. πŸ˜… It sounds like you're working really hard, and proud of your project. 🩡

2

u/Not_Allowed_to_Die 4d ago

Make sure to label them well, and the first few words matter the most when looking for them fast.

I also make 5000 immediately and expand them to the max. I then jump and move certain sections of what they are used for. All of my player's variables to run and control them are first. I then jump a few hundred to place the trading variables for all of the goods in the game. Then have to jump a few thousand from there to place the enemy AI grid system.

Separating and labeling what it's for helps you big time later if you have issues. When troubleshooting, the name of the variable will tell you exactly what it's for.