Charles2020

Veteran
Veteran
Joined
Feb 24, 2020
Messages
108
Reaction score
4
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,601
First Language
English
Primarily Uses
RMMV
Try 3 "=" instead of 2.
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,050
Reaction score
7,976
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,601
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,255
Reaction score
1,663
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
108
Reaction score
4
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,255
Reaction score
1,663
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

AeroPergold wrote on LUKElcs's profile.
Its-a me, Pergold from Gamejolt!
I added footstep sounds to our content that I posted in a previous thread. I was unable to edit the post, so if you're interested, see below.

DOWNLOAD LINK

I've started working on rpg maker again, and I can see a lot of improvement from when I was 13. I still have a long way to go, but I'm proud that I've gotten this far.
Animated Title screen is by SharkerrBlue(SB)
I am using the Nightmare Land pack.
I just can't walk to the store for lunch without walking past people smoking. It not only smells bad, it's probably poisoning me. I'm afraid I'll eventually have to be hospitalized. I can't take another path because there's too much traffic and drivers in the plaza are reckless sometimes. I almost got run over once, even after looking both ways.
RyanYe wrote on whtdragon's profile.
Your art works about Wyrvens and Dragons are sooooooooo cooooooooool~! I like them so bad
Can you create more? like Archangels, Devils, Titans, Cyclops!!

Forum statistics

Threads
108,808
Messages
1,039,634
Members
141,254
Latest member
wuyuzhi
Top