RMMV compare variable using select item command

Charles2020

Veteran
Veteran
Joined
Feb 24, 2020
Messages
99
Reaction score
3
First Language
English
Primarily Uses
RMMV
Hi guys

I have a question

I used the select item command to assign to variable 10 and wanted to compare if the variable is item A (number 3)

I tried below but did not work

If $dataItems[$gameVariables.value(10)] == 3 else ....
If $gameVariables.value(10) == 3 else ...

Any suggestions?

thanks
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,819
Reaction score
1,582
First Language
English
Primarily Uses
RMMV
Try 3 "=" instead of 2.
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,734
Reaction score
7,851
First Language
German
Primarily Uses
RMMV
why use javascript after an event command? a conditional branch on the variable directly without script would be easier.

that said, your mistake is using the wrong operator. comparison in javascript is === (three, not two equals)

Try 1 "=" instead of 2.
one equal is assignment, that won't work either
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,819
Reaction score
1,582
First Language
English
Primarily Uses
RMMV
why use javascript after an event command? a conditional branch on the variable directly without script would be easier.

that said, your mistake is using the wrong operator. comparison in javascript is === (three, not two equals)

one equal is assignment, that won't work either
Ah ur right, I had a brain fart lol, I'll edit that. This should be what @Andar mentioned:
(eventing instead of script)
1606428337345.png

But regarding "="...I thought "==" & "===" were both for comparisons, the former being soft and the latter being hard. I sometimes use "==" instead of "===" when it's not necessary and works fine. It's only when the values are different types does it matter, right?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,219
Reaction score
1,629
First Language
EN
Primarily Uses
RMMZ
Yea, I'd just use event commands here~ :kaoslp:

For a pure-script approach (e.g. part of a Script command) you need brackets around the condition:
JavaScript:
if ($gameVariables.value(10) === 3) {
  // stuff goes here
}
More details here:

Details on comparison types here:
 
Last edited:

Charles2020

Veteran
Veteran
Joined
Feb 24, 2020
Messages
99
Reaction score
3
First Language
English
Primarily Uses
RMMV
But does this apply to item number ?

Would it be something like

If ($dataItems[$gameVariables.value(10)] === 3 )
{ ...}
else ....
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,219
Reaction score
1,629
First Language
EN
Primarily Uses
RMMZ
If ($dataItems[$gameVariables.value(10)] === 3 )
{ ...}
else ...
$dataItems is an array of objects, not numbers. I don't think it's possible for the check you've written to be true unless the database is malformed. :kaoslp:

(Also, note that JavaScript is case-sensitive: it's if, not If.)

The Select Item command returns the ID of the selected item, i.e. a number. Try it and see for yourself!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

It was my birthday yesterday woooo /) ~ 3 ~)/)~~
Around 5am and can't sleep...It happens! Been a productive night at least!
Got my portraits working with a plugin, rather then "Show Picture" since that was too long of a process and I'm sure would have ended up with massive lag
To composers out there, what are atleast 4 instruments overall I need to have to make my music not feeling empty? I'm here stuck trying to make my own battle music but it kinda sounds... Not intense?
My computer broke yesterday, so no RPG maker for at least a week until I can get it repaired. :(
Just wanted to share how my game won 1st place in a game jam for itch.io. Everyone else used Unreal, Unity, GMS2, Godot, etc but I used RPG Maker 2003 :guffaw: It just shows that you can create a good game and it doesn't matter which engine you use

Forum statistics

Threads
107,411
Messages
1,029,485
Members
139,522
Latest member
Pixelated_Trees
Top