RMMV Hey kids, don't forget that "=" and "==" are different.

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
78
Reaction score
47
First Language
English
Primarily Uses
RMMV
If you're just getting into JavaScript, you might start getting fancy with your "Conditional Branches" and start using scripting instead of just the default values. When you do, it's really important to remember that "=" is the assignment operator, while "==" is the equality operator. "==" asks if two things are equal, while "=" overwrites the value on the assigned on the left with whatever value is on the right.

As an example, here's what took me literally hours to figure out this evening, because I forgot this simple fact.

1623661676941.png
This is bad. It forces the length of variable 312 (which is an array, though that's not really important) to become 0. It's bad for 2 reasons.
1. This isn't a question, so there isn't a chance for it to evaluate as true, which means that anything inside the if statement is never going to be done. In this case, that means an infinite loop, which is always just fantastic.
2. It overwrites whatever was in variable 312 with 0. In this case, since it's setting the length of variable 312 to zero, it's actually setting the value of 312 to [ ], removing all contents and making a mess of my evening that took hours of debugging and me being an idiot to sort out.

Here's what it was supposed to be
1623661974251.png
Now, it's actually checking the condition properly, and not overwriting the information with whatever garbage I accidentally turned it into.

Don't be like me kids. Always remember that "=" and "==" are different.
 

NeptuneTron

The Salticid Scholar of the North
Veteran
Joined
Jan 13, 2018
Messages
78
Reaction score
47
First Language
English
Primarily Uses
RMMV
BONUS TIP:

If you're having issues debugging your code, try including some kind of heading with your debug messages, so that it's clear what part of your code you're actually in.

Repeating console.log($gameVariables.value(312)) after every single line makes it really difficult to which particular line is causing the problem. If you include a heading or some other information to easily differentiate between steps, you'll find your life much easier.
 

Tiamat-86

old jrpg gamer
Veteran
Joined
Dec 5, 2017
Messages
747
Reaction score
337
First Language
english
Primarily Uses
RMMV
this level of detail explaining javascript if what i need.
if you could work together with Trihan and what they've already made, adding this level of detail in explaining all aspects of javascript it would be totally next level is helping a scripting full on noob like me understand what im actually looking at.
 

Nolonar

Veteran
Veteran
Joined
Feb 18, 2018
Messages
241
Reaction score
351
First Language
French, German
Primarily Uses
RMMZ
1. This isn't a question, so there isn't a chance for it to evaluate as true, which means that anything inside the if statement is never going to be done. In this case, that means an infinite loop, which is always just fantastic.
Actually, it's both an assignment and a question. If you hadn't set the length to 0, but to 1 (or any other number) instead, you would've always entered the conditional.

One cool thing about JavaScript (and most C-inspired languages), is that assignments also return a value. For example, you can do something like:
Code:
x = y = 0;
instead of:
Code:
x = 0;
y = 0;

You can also do something like:
Code:
if (this._isEnabled = result) {
   // do something
}
instead of:
Code:
this._isEnabled = result;
if (this._isEnabled) {
    // do something
}

I don't recommend using the second shortcut, because it's hard to tell if that's what you intended, or if it's a typo.

Also, JavaScript has two equality operators, == and ===. I recommend only using === and avoiding == if you can (https://stackoverflow.com/q/359494/1169228).
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,307
Reaction score
703
First Language
English
Primarily Uses
RMMV
this level of detail explaining javascript if what i need.
if you could work together with Trihan and what they've already made, adding this level of detail in explaining all aspects of javascript it would be totally next level is helping a scripting full on noob like me understand what im actually looking at.
Have you tried any tutorials? Forget RPG Maker, just JavaScript tutorials. There are plenty that start at the beginner level.

Sites like javascript.info and w3schools.com have beginner tutorials, so they definitely cover very basic information like this. javascript.info is text-based, so you need to experiment on your own, but w3schools has code boxes on the page for you to type the examples into and see how they work.

These are just the first two things that come up when I Google "JavaScript tutorial."
 

Latest Threads

Latest Posts

Latest Profile Posts

Ami
need a time to not open my MV,still addicted with new vegas

i wonder what addiction effect behind playing new vegas too much,maybe INT & Science gone worse in many days :D
cdjensen94 wrote on Kaliya's profile.
Are you the one who develops Kaliya's Visual Map Enhancements. If so I desperately need some help. I bought the plugin back a few months. I've only started using it recently.
Cause MP Damage instead of HP, Localization Plugin for Translation | RPG Maker News #112

Here in Fla were are seeing crazy covid spikes and some vaccinated getting bad infections. I had a mild fever on Thurs but it went down fast. How is everyone else doing. Hopefully you are all well. :)
Wish I was better at art, specifically that I was faster at it, bc this one NPC took Several Days to complete! It's gonna take So Extremely Long to do all of the art for my game, never mind writing it... Anyways, here's my gorgon, Hopernica Sthyxis!

57b88732c7abbcd84981dacf624a98495af61fcc.gifv

Forum statistics

Threads
113,826
Messages
1,077,737
Members
147,883
Latest member
Senppai90
Top