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

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,768
Reaction score
7,869
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,598
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,224
Reaction score
1,631
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,224
Reaction score
1,631
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 Profile Posts

Is this Profile Banner thing new? Or did I just discovered it now?
Well.. I was going to post my randomly generated road experiments... But the new "Attach Files" on profile posts seems to be quite buggy. Also there's no more option to insert Imgur images. Highly unfortunate. Guess I'll give them a bit to fix it and go back to messing with stuff.
my first day back to working on my project and i'm pooped!! hope to get back in the rhythm soon!

Forum statistics

Threads
107,595
Messages
1,030,826
Members
139,701
Latest member
beccokiwis
Top