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

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,763
Reaction score
7,865
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,835
Reaction score
1,593
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,223
Reaction score
1,630
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,223
Reaction score
1,630
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

After hearing Wataten's opening several times and knowing what this anime is about, I don't think I like moe anymore.
So I am working on a big DLC package for my game.... and it will add a new intro and extend the ending of the base game, while of course adding additional content to the game... Yeah, that should work! lol
I'm stuck, I'm making some of Mr. N's Dialogue but I can't finish his full Dialogue...heres what I got now [this is the part I'm stuck on] "You treat me like a
bug, I'M SICK OF IT, you had me make these...abominations...well, now..." and at the "Well, now...' part I'm stuck at, anyone got Ideas?

Forum statistics

Threads
107,548
Messages
1,030,428
Members
139,673
Latest member
WDRS
Top