The same command chain works for some variables but not others? Please help!

Status
Not open for further replies.

Ratatattat

Villager
Member
Joined
Mar 22, 2020
Messages
7
Reaction score
2
First Language
English
Primarily Uses
RMMV
Hello! I just made this account and though I've read lots of threads here before, have never posted. I am also very new to Javascript although I've picked some things up. So I apologize if this is in the wrong forum, or my terminology is off, or anything like that.

I'm creating an alchemy system where the player can choose three ingredients that they have, then those chosen ingredients are compared against all established "recipes" (specific sets of ingredient IDs) to see if any match. If so, they create a specific potion. If not, they create "Unidentifiable Sludge" and lose the ingredients. The variables used to store the chosen ingredient IDs are reset to 0 after each use, for a clean slate for next time.

Anyway, my issue is this:
I have four test recipes right now and only three of them work. They are all set up exactly the same, with the only thing differing being the IDs of the target ingredients. I noticed that the only thing that sets the non-working one apart from the others is that, while the target ingredient IDs for the first three are all single-digit values and thus formatted like "000x", two of the target ingredients in the non-working one have two-digit ID values and thus are formatted like "00xy".

I cannot even begin to fathom why this would make a difference. I changed these two-digit IDs to single-digit ones to rule out anything else, and voila! It suddenly worked! Changed them back to the original two-digit IDs, and it's not working anymore. I have double, triple, quadruple checked that I am using the correct item IDs. At the end of the day, something about those lines of script isn't compatible with "00xy" values or something, and I don't know why and don't know how to fix it...

I've included annotated screenshots to help with following along!

Anyone with more JS knowledge who knows what's going on or how I can fix/get around it? Thank you so much in advance!!
<3
 

Attachments

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,093
Reaction score
1,509
First Language
EN
Primarily Uses
RMMZ
Note that something like $gameVariables.value(9) === 13 simply says "is the value of game variable 9 currently equal to 13?". There is absolutely no need to use a script call for those conditions, since you can directly check a variable's value against a constant or another variable using the Conditional Branch > Variable event command. There might be other issues, but I'd try swapping out your script conditions first to see if that fixes it. :kaothx:

Also, in JavaScript leading zeroes on integers are unnecessary, and can cause issues if your project code is sufficiently old (pre-ES6, which I think is v1.5.1 or earlier). E.g. 0007 would be interpreted as "octal 7" which is equal to 7 in base-10 (a.k.a. decimal); 0013 would be "octal 13", which is 11 in decimal. :kaoback: This would affect your loseItem/gainItem script calls, especially since octal doesn't have "8" and "9" digits. I assume it would fall back to decimal for those, along with warnings in the console (F8 during test-play). :kaoslp:

(For non-integers you can safely include a zero before the point, e.g. 0.9. :kaophew:)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,370
Reaction score
7,678
First Language
German
Primarily Uses
RMMV
leading zeros in scripts are always unneccessary for anything done in the RMs, even older ones with RGSSx.
And it has always caused problems exactly because it results in octal interpretation of the numbers.

The leading zeroes are only in the editor due to the way how the display is formatted, they should never be included in script based numbers.
 

Ratatattat

Villager
Member
Joined
Mar 22, 2020
Messages
7
Reaction score
2
First Language
English
Primarily Uses
RMMV
Note that something like $gameVariables.value(9) === 13 simply says "is the value of game variable 9 currently equal to 13?". There is absolutely no need to use a script call for those conditions, since you can directly check a variable's value against a constant or another variable using the Conditional Branch > Variable event command.
Oh DUH!! This is exactly the perspective I needed, I've been so wrapped up in all this I didn't see the obvious LOL. I think the original reason I used a script was because I wasn't sure whether the leading zeroes were important, and I originally resorted to script instead because when I entered them in the Conditional Branch>Variable window, it defaulted from 000x format to just x. I should have taken that as a clue, duh!!

Also, in JavaScript leading zeroes on integers are unnecessary, and can cause issues if your project code is sufficiently old (pre-ES6, which I think is v1.5.1 or earlier). E.g. 0007 would be interpreted as "octal 7" which is equal to 7 in base-10 (a.k.a. decimal); 0013 would be "octal 13", which is 11 in decimal.
leading zeros in scripts are always unneccessary for anything done in the RMs, even older ones with RGSSx.
And it has always caused problems exactly because it results in octal interpretation of the numbers.

The leading zeroes are only in the editor due to the way how the display is formatted, they should never be included in script based numbers.
In any case, while this language is pretty foreign to me, it's enough for me to understand that at least there is a reason why these zeroes would make a difference, and that I'm not just going crazy!! Very good to know that the zeroes aren't needed. I was worried it had to be exact and I was so wrapped up in trying everything else that it hadn't even crossed my mind to try without. Case closed! :)

Thanks so much, guys!
<3
 

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,536
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

"You can thank my later", "But you haven't done anything", "Well, that's why ..."
Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

Forum statistics

Threads
105,884
Messages
1,017,243
Members
137,609
Latest member
shododdydoddy
Top