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,846
Reaction score
1,599
First Language
English
Primarily Uses
RMMV
Try 3 "=" instead of 2.
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,821
Reaction score
7,886
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,846
Reaction score
1,599
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,227
Reaction score
1,634
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,227
Reaction score
1,634
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!
 

Latest Threads

Latest Posts

Latest Profile Posts

Anyone else having trouble posting in the forum? I have no reply box in posts or in messages. This is the only place I can type. @Archeia?
Snarkyfork wrote on Trihan's profile.
Hey man, I saw you mention that you do MV javascript work? Just wanted to confirm it before I put you on speed dial. =)
"Man is made by his belief. As he believes, so he is."-Krishna
FastFood in my country is neither fast nor cheap like it's expected to be, but people still buy a lot of it. I don't want to imagine how much of it people would eat if it was.

Forum statistics

Threads
107,763
Messages
1,031,974
Members
139,906
Latest member
xana_the_machine
Top