How to set a Common Event equal to a variable?

Almouros

Warper
Member
Joined
Jul 4, 2022
Messages
1
Reaction score
1
First Language
English
Primarily Uses
RMMV
So, I am pretty new to rpg maker, but i am wanting to have a text show up each time the player gains an item and have it displayed as "You gained "Item Name""
So far, i have in the common event is "You gained \v[1]" and i want to set the value of the variable 1 to the name of the item without having to type it all out each time.
I.e
Common Event: "You gained..."
Text: "You have gained \v[1]"

Player opens chest to gain a sword
Set Variable#1=Item(Sword)
Common Event: You gained....

Displays: You have gained 1 SWORD.


Hope this makes sense!
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
511
Reaction score
490
First Language
English
Primarily Uses
RMMZ
You can set a variable to have a string value by going to the control variables dialogue, and clicking on the radio button that says Script. Then in the box next to it, type your string, surrounded by quotation marks. So if the item's name is Sword of Doom then type:
Code:
"Sword of Doom"

But honestly, is that really going to save you much time/work? Having to set up the variable and call the common event every time isn't really any harder than just showing the message manually. If you wanna save yourself some work, then a plugin might be a better option instead. There should be one in your DLC folder, in a folder named Kadokawa Plugins. I think it's called TinyGetInfoWnd, or something like that. It should automatically display any items you gain in its own special window. There are other options on the internet as well.
 

Zevia

Veteran
Veteran
Joined
Aug 4, 2012
Messages
677
Reaction score
406
First Language
English
Primarily Uses
RMMV
But honestly, is that really going to save you much time/work? Having to set up the variable and call the common event every time isn't really any harder than just showing the message manually.
Until you decide you want to change the name of the item or how the message displays, in which case you'd have to go back through every event and edit them, instead of changing one common event.

On that note, I'd actually recommend making a different variable for each item name instead of reusing the same variable every time. Something like:
  • Common event has "You gained \v[1]"
  • At the beginning of the game, there's an event that says "variable 2, doomSwordName = 'Sword of Doom', variable 3, potionName = 'Healing Potion'", etc. Finally have a variable like "variable 1, itemGained"
  • When giving the player an item, set variable 1 = variable 2, or variable 1 = variable 3, then call your common event
Then, if you want to change "Healing Potion" to "Health Potion", you only have to change the one event at the beginning of the game where you named variables 2, 3, etc. If you want to change how the display message looks, you only change the common event.

Archeia recommended making a common event for giving items to players when I was new to RPG Maker and I ignored the advice and just put it in my events manually. Then I decided I wanted to add icons later. It took a lot of work and I missed some that I had to keep going back and changing every time I'd find a missed one. I could've saved so much time and QA by making things reusable as possible.

If you wanna save yourself some work, then a plugin might be a better option instead.
If you're new to RPG Maker, Plugins can be really helpful and save you a lot of time, but keep in mind they aren't typically tested for compatibility with each other or even properly tested within their own functionality. It's common for new devs to go Plugin-crazy and just grab one for everything, but there's a lot of value in learning what the engine can do on its own and only look for Plugins where there's a significant gap in functionality you need (like overhauling the battle system or, as mentioned, if you want item gains to be in a separate special window).
 

Arthran

Veteran
Veteran
Joined
Jun 25, 2021
Messages
511
Reaction score
490
First Language
English
Primarily Uses
RMMZ
Until you decide you want to change the name of the item or how the message displays, in which case you'd have to go back through every event and edit them, instead of changing one common event.
That's fair. In that case, rather than doing the ton of variables thing, I'd probably just pull the name straight from the database. That way you save yourself a bunch of variables, and you don't have to go check which variable you assigned to which item every time you create a new event, and if you want to change a name later on, you only have to change it in the database. Supposing it's a weapon, put this in the script box of the control variables command:
JavaScript:
$dataWeapons[Id].name
Of course, you'd replace Id with the numerical ID of the weapon.

For an armor:
JavaScript:
$dataArmors[Id].name

For an item:
JavaScript:
$dataItems[Id].name

Though I'd personally still do this via plugin.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

Coin Locker title screen:
Still in progress...

Screenshot_134.png
the girls.png
So, these are all the girls of the party =3 (beside the protagonist if you play as a female.)
Now, I just have one more character sheet of the guys left and I'm done with their presentations =3
Can you recognize where this area is from? :kaocry:
Mq9QM3h.png
For those with up to 9 elements of magic; how do you structure your database. By element? Or by what is offensive vs supportive spells?
would anyone here be interested in rough concept art for the main protagonist of my game that might get changed later? :kaoswt2:

Forum statistics

Threads
124,442
Messages
1,163,677
Members
163,256
Latest member
onbetltd
Top