Need help with learning to read a javascript

Status
Not open for further replies.

KingLi

Villager
Member
Joined
Mar 19, 2018
Messages
22
Reaction score
5
First Language
English
Primarily Uses
RMMV
So i was looking around and i found this

for (var i = 0; i < $targetCardPlayer.hand.length; i++) {
var card = $targetCardPlayer.hand;
$calc.list.push(card);
}

This is a code for a card game and that it shows me the opponent's hand. So I'm wondering how to read this javascript.
  • I know var i =0 which is less than the opponent's hand and repeat for i++ for every other card in the opponent's hand.
But I do not know how

var card = $targetCardPlayer.hand;
$calc.list.push(card);

is read.
 

marsatche

Strawbebby
Member
Joined
Jan 28, 2020
Messages
27
Reaction score
23
First Language
English
Primarily Uses
RMMV
I'm guessing that var card is to store the current card that the player has, then stores (pushing it) to the list inside $calc variable. Possibly this $calc is used somewhere else to perform... damage calculation?

$targetCardPlayer.hand is a list of some sort to store the active cards.

And it will do this process until the for loop finishes reading every card the target player is holding at hand. ((Correct meh if I'm wrong orz))
 
Last edited:

KingLi

Villager
Member
Joined
Mar 19, 2018
Messages
22
Reaction score
5
First Language
English
Primarily Uses
RMMV
I'm guessing that var card is to store the current card that the player has, then stores (pushing it) to the list inside $calc variable. Possibly this $calc is used somewhere else to perform... damage calculation?

$targetCardPlayer.hand is a list of some sort to store the active cards.

And it will do this process until the for loop finishes reading every card the target player is holding at hand. ((Correct meh if I'm wrong orz))
Hmmmm could be. Gonna learn to read javascript and other people custom javascript oh dear me XD
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,118
Reaction score
1,526
First Language
EN
Primarily Uses
RMMZ
@marsatche is correct~
  • for (var i = 0; i < $targetCardPlayer.hand.length; i++)
    A for loop: repeat the following {block} of code.
    1. Define a variable i that starts with a value of 0.
    2. Before running the code, check if i is less than the number of items in the array named $targetCardPlayer.hand: if it isn't, skip the code block and end the loop.
    3. After running the code, increase the value of i by 1 and return to step 2.

  • var card = $targetCardPlayer.hand[i];
    Define a new variable called card, and set it equal to the ith item in $targetCardPlayer.hand.

  • $calc.list.push(card);
    Add card as a new entry to the end of the array stored in the list property of the $card object.
These lines all involve Arrays, see here for more details: Array (MDN).

If you don't know what I mean by words like "object" or "property", then maybe hunt around for tutorials on the basics of object-oriented programming ("OOP"): classes, objects, properties, methods, inheritance, etc. JavaScript uses a slightly different structure to many OOP languages...you can read up on the details here, but it may not make much sense if you're a total beginner. :kaoswt2:


Also, about that disappearing [i] in your post: [i] is interpreted as a post-formatting tag here (and on many forums). To avoid this, you can use a code block, either by using the Insert > Code button from the toolbar (just above the textbox where you type out your post) or by writing it out like [code]This is code[/code]; it will appear like this:
Code:
for (var i = 0; i < $targetCardPlayer.hand.length; i++) {
  var card = $targetCardPlayer.hand[i];
  $calc.list.push(card);
}
:kaopride:
 

KingLi

Villager
Member
Joined
Mar 19, 2018
Messages
22
Reaction score
5
First Language
English
Primarily Uses
RMMV
@marsatche is correct~
  • for (var i = 0; i < $targetCardPlayer.hand.length; i++)
    A for loop: repeat the following {block}of code.
    1. Define a variable i that starts with a value of 0.
    2. Before running the code, check if i is less than the number of items in the array named $targetCardPlayer.hand: if it isn't, skip the code block and end the loop.
    3. After running the code, increase the value of i by 1 and return to step 2.

  • var card = $targetCardPlayer.hand[i];
    Define a new variable called card, and set it equal to the ith item in $targetCardPlayer.hand.

  • $calc.list.push(card);
    Add card as a new entry to the end of the array stored in the list property of the $card object.
These lines all involve Arrays, see here for more details: Array (MDN).

If you don't know what I mean by words like "object" or "property", then maybe hunt around for tutorials on the basics of object-oriented programming ("OOP"): classes, objects, properties, methods, inheritance, etc. JavaScript uses a slightly different structure to many OOP languages...you can read up on the details here, but it may not make much sense if you're a total beginner. :kaoswt2:


Also, about that disappearing [i] in your post: [i] is interpreted as a post-formatting tag here (and on many forums). To avoid this, you can use a code block, either by using the Insert > Code button from the toolbar (just above the textbox where you type out your post) or by writing it out like [code]This is code[/code]; it will appear like this:
Code:
for (var i = 0; i < $targetCardPlayer.hand.length; i++) {
  var card = $targetCardPlayer.hand[i];
  $calc.list.push(card);
}
:kaopride:
Ah, thanks for the help this post has been solved! :)
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,867
Reaction score
5,240
First Language
Dutch
Primarily Uses
RMXP

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 Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,051
Messages
1,018,549
Members
137,837
Latest member
Dabi
Top