Need help with a javascript command

for the javascript that i'm checking out

for (var i = 0; i < $userCardPlayer.discard.length; i++) {
var card = $userCardPlayer.discard;
if (card.element().toUpperCase() === 'NONE') {
$userCard.gainLevel(1);
$userCard.gainPower(1);

What does i++ mean? And how do i use it?
it means increment variable by 1. so the variable i is having 1 added to it. it's shorthand for let i = i + 1.

it means increment variable by 1. so the variable i is having 1 added to it. it's shorthand for let i = i + 1.


Ah thank you, also do you have a recommended place for me to learn javascript for games?
Like the above post said, it means that the variable i will have its value increased by one after each loop. i++ is just another way of saying i = i + i;

The for loop increments at the end of one cycle, meaning i starts off at 0, the CPU goes through the loop once, then adds +1 to i, then regoes through the loop, then i+1, etc.

Btw there's an obvious error in your loop. $userCardPlayer.discard is clearly an array (since you have a .length method after it). In your loop you refer to the array itself, not the elements inside. It should be: var card = $userCardPlayer.discard[i] .

Also, you should check your brackets {} since they seem to be missing closing ones.
Like the above post said, it means that the variable i will have its value increased by one after each loop. i++ is just another way of saying i = i + i;

The for loop increments at the end of one cycle, meaning i starts off at 0, the CPU goes through the loop once, then adds +1 to i, then regoes through the loop, then i+1, etc.

Btw there's an obvious error in your loop. $userCardPlayer.discard is clearly an array (since you have a .length method after it). In your loop you refer to the array itself, not the elements inside. It should be: var card = $userCardPlayer.discard[i] .

Also, you should check your brackets {} since they seem to be missing closing ones.

Can you tell me more about the

var card = $userCardPlayer.discard

Why should I put an in there and how it fix it?
Can you tell me more about the

var card = $userCardPlayer.discard

Why should I put an in there and how it fix it?
You seem to be a beginner in javascript, so I would suggest you go follow a tutorial on the language (and notions that are common to all programming languages). You need to learn and be familiar with the basic notions like what's an integer, a float, a Boolean, conditionals, incremental, inheritance, different types of loops, etc.

The problem with the line var card = $userCardPlayer.discard is that it refers to an array (presumably, that object is not a default object in RPG Maker and I don't know what plugin you are using), and not an element of the array (which is what you want within the loop). Basic the loop that you posted means something like "Okay, I have a group of cards in $userCardPlayer.discard, and I want to go through every card in the group and do a certain operation with every card".

So the correct way of doing the loop would be (with the commentary to help you understand):
Code:
for (var i = 0; i < $userCardPlayer.discard.length; i++) {

    // Select the card from the array of cards, hence the [i].
    // By making i gain +1 at the end of the loop, it's like you're picking
    // the next card in the group and going through the same code.
    var card = $userCardPlayer.discard[i];
  
    // Do the operation you want to accomplish with that card for this loop.
    // Although I don't know what $userCard refers to. In this example, I don't
    // understand the utility of defining card if you won't mention it afterward.
    if (card.element().toUpperCase() === 'NONE') {
        $userCard.gainLevel(1);
        $userCard.gainPower(1);
    }
  
}

EDIT: It's really hard to help you in this particular case since I have no idea what you are trying to accomplish, and I have no idea how the plugin for cards you are using works. I'm just giving explanations in a general way, not specific to this case.
it means increment variable by 1. so the variable i is having 1 added to it. it's shorthand for let i = i + 1.


Is https://www.w3schools.com/ a good place to learn javascript?
Is https://www.w3schools.com/ a good place to learn javascript?
I didn't use that to learn coding so I can't comment on the quality of the education there, but I regularly use that site for functions and methods that I forget and that are essential (methods for strings for instance). So yes, as a source of practical knowledge in javascript, that site is good.
I didn't use that to learn coding so I can't comment on the quality of the education there, but I regularly use that site for functions and methods that I forget and that are essential (methods for strings for instance). So yes, as a source of practical knowledge in javascript, that site is good.

What website did you use to learn java?
What website did you use to learn java?
I didn't use a website, I watched a video on youtube teaching javascript for programmers since I already knew C# and Ruby. A lot of the basics in programming is similar for almost all languages (for example integer, arrays, strings, etc.), so when learning a new language all we have to do is learn the syntax and the libraries since we already know the rest.

Additionally java is a separate programming language from javascript. The naming might be confusing for non programmers, but they are really different programming languages.

Also, let's not derail the thread from the topic. If you want to discuss about good tutorials for learning javascript you can create another thread for that. For now, if your question here has been answered, you can ask me to close the thread (this system is to allow people with similar questions as you to find this thread in the future).
I didn't use a website, I watched a video on youtube teaching javascript for programmers since I already knew C# and Ruby. A lot of the basics in programming is similar for almost all languages (for example integer, arrays, strings, etc.), so when learning a new language all we have to do is learn the syntax and the libraries since we already know the rest.

Additionally java is a separate programming language from javascript. The naming might be confusing for non programmers, but they are really different programming languages.

Also, let's not derail the thread from the topic. If you want to discuss about good tutorials for learning javascript you can create another thread for that. For now, if your question here has been answered, you can ask me to close the thread (this system is to allow people with similar questions as you to find this thread in the future).

Yeah I shall create another tread. Thanks for the help 🙂
@KingLi Shall I mark the thread as solved and close it?
@KingLi Shall I mark the thread as solved and close it?

Yes It has been solved 🙂

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.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-a-javascript-command.117901/