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,087
Reaction score
1,508
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
31,359
Reaction score
7,672
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.

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

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
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

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top