How to check if a particular item was selected?

Status
Not open for further replies.
Joined
Apr 7, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
I'm starting an event command... 'Select Item'

Then I store the item id in a variable. I want to check if the item selected was 'Sword'. How do I do this?

I don't know how to access the id of the 'Sword' item. Do I have to store it in another variable, then compare the two variables?

Thanks.

EDIT: Never mind. I completely forgot that every item has an id that is accessible in the Database/Items menu.
 

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
Hey, how did you actually do a check though? Is there a command to check for which ID (item) was selected?
 
Joined
Apr 7, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
Hey, how did you actually do a check though? Is there a command to check for which ID (item) was selected?

So first you select an item and put it into a variable... say the variable is:

0003 item_selected
as listed in the variables

Also supposed the item you want to check for is

0002 Magic Water
as listed in items

So after you select the item, you can put in a conditional branch with script and in the script you can put:

$dataItems[$gameVariables.value(3)].name=='Magic Water'

So if you selected magic water it will go into the conditional branch. That's how I did it.
 

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
Got this working beautifully, so thank you for that!
I was wondering what I could do with this line of code: "$dataItems[$gameVariables.value(10)].name == "item_Name""
to modify it, such that if the player presses the Escape key while 'Select Item' is being used.
I'm getting an "null name" error since I click the Escape key before making a selection of an item (thus not giving a name to the variable which is searching for the ID of the item).
Is there a way to recognize the escape key (WHILE being in item select)?
 
Joined
Apr 7, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
The way I handled that is... at the top you first set your variable (where you store your item) to -1... or some dummy value that indicates a selection hasn't been made.

When a valid selection is made the variable will be 0 or greater. When cancel is hit the variable stays at -1.

So after the select item command, you use a conditional branch... and select your variable and set condition >= constant 0.

And then you put all your code that you want to run after a valid selection under that conditional branch.

If you hit cancel, your variable stays at -1 and it should skip over the whole branch.
 
Last edited:

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
This doesn't seem to be working for me. I have multiple items being selected from and I want the player to choose of the 7 or 8 choices of items to give. Each item will affect a meter in a different way.

I have it set up in order of logic:
set variable to -1
Select Item
If Button is Cancel (keeps variable @ -1, can include break loop)
If variable >= 0, then perform all the gamedata code and item code)

This doesn't seem to work though, and still gives me name null.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,417
Reaction score
1,827
First Language
EN
Primarily Uses
RMMZ
Right idea, just change your condition to "variable > 0" and I think it should work out. :kaothx:

($dataItems[0] is null, which explains the error. :kaoswt:)

Also, you don't need to set the variable value beforehand: it should set it to 0 if you don't pick an item, or the item ID if you do. ^_^
 

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
Perfect! Just got it fixed and working! Appreciate the help!
 
Joined
Apr 7, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
Ah, caethyril is right. I'm still a noob at this. No need to set the variables in advance... and cancel sets the variable to 0, so we need >0 as the condition.
 

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
Yea! Checks out!
No worries, I appreciate your help either way!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,539
Reaction score
8,154
First Language
German
Primarily Uses
RMMV
$dataItems[$gameVariables.value(3)].name=='Magic Water'
and that is a really cumbersome way to test.

you can test the item ID directly with the conditional branch, just use variable(ID) equals the IDnumber of the magic water directly, which is the number of it in the database list.
Absolutely no need to compare the names - just remember to remove any leading zeroes. If the database lists 0002 Magic Water, then the ID itself is 2
 

favbot

Villager
Member
Joined
Mar 31, 2019
Messages
13
Reaction score
5
First Language
English
Primarily Uses
RMMV
Ah so just checking the values together and seeing if the ID number matches? Gotcha! Thanks for the advice!
 
Joined
Apr 7, 2019
Messages
21
Reaction score
10
First Language
English
Primarily Uses
RMMV
and that is a really cumbersome way to test.

you can test the item ID directly with the conditional branch, just use variable(ID) equals the IDnumber of the magic water directly, which is the number of it in the database list.
Absolutely no need to compare the names - just remember to remove any leading zeroes. If the database lists 0002 Magic Water, then the ID itself is 2

You're right. Not sure why I did it this way.
 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

Arcade-Style RPGM Games? RM2k3 Game Jam & Synth-Retro Music by Azakaela | RPG Maker News #39

Just evented my first minigame, no plugins~ :kaojoy:
I feel still screenshots don't do my game justice. the characters don't move, but the filter over them does...
Wonder if this year, there be more MZ plugin than MV or that MZ is still small compare to whole MV collection
Zaj
Hey morning all! I got another quick question..I just switched to RMMZ from VX Ace..so I am wondering why default scripts(is that how u call it) of VXAce is available, but not in MZ's case? How do I figure out ahh I mean could you show me

Forum statistics

Threads
111,346
Messages
1,060,376
Members
144,674
Latest member
WaterIce455
Top