.push() is not a function ._. [solved]

Status
Not open for further replies.

Nilom

Veteran
Veteran
Joined
Sep 9, 2013
Messages
178
Reaction score
40
First Language
German
Primarily Uses
RMMV
Hello!

I used .push() for a card drawing skill system before.

But when I try to do something similar and store movement commands (numbers) inside an array then I get ".push()" is not a function.

What did I do wrong? I just do not see it:

Code:
if ($gameMap.regionId($gameMap.event($turn_number).x-1,$gameMap.event($turn_number).y) == 8) {
    $look_dir[$turn_number] = 17;
    $backfinding[$turn_number].push(18);
    console.log("look_dir: left");
}
if ($gameMap.regionId($gameMap.event($turn_number).x+1,$gameMap.event($turn_number).y) == 10) {
    $look_dir[$turn_number] = 18;
    $backfinding[$turn_number].push(17);
    console.log("look_dir: right");
}
if ($gameMap.regionId($gameMap.event($turn_number).x,$gameMap.event($turn_number).y-1) == 1) {
    $look_dir[$turn_number] = 19;
    $backfinding[$turn_number].push(16);
    console.log("look_dir: up");
}
if ($gameMap.regionId($gameMap.event($turn_number).x,$gameMap.event($turn_number).y+1) == 17) {
    $look_dir[$turn_number] = 16;
    $backfinding[$turn_number].push(19);
    console.log("look_dir: down");
}
Note that it is intended that I mirror the direction numbers. Because "backfinding" is all the commands from "pathfinding" backwards.




Thanks in advance! :)





Edit:
Nevermind, I found the issue. I was defining $backfinding wrong.
What I did:
Code:
$backfinding = [0, 0, 0, 0, 0]
What I should have done:
Code:
for (var i = 4; i > 0; i--) {
$backfinding[i] = []
}
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,774
Reaction score
4,718
First Language
English
Primarily Uses
RMMZ
I don't know about the plugins you are using or the code you wrote, but if you console.log $backfinding[$turn_number] what does it show? .push() works on arrays, so if it's trying to use .push() on an integer or something it will display an error.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
8,011
Reaction score
5,325
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 Posts

Latest Profile Posts

Made a surprising amount of progress in these past two days. Really helps when parallax mapping breaks limitation and allowing me to be creative and make maps that match my vision.
Let's promote our amazing artists in RPG Maker community! I posted right now about my game Phil Alone on Twitter and I decided to thanks Lime Zu, the amazing artist that did all the pixel assets for my game!
I just realised that the reason behind me not being able to make a game may be the lack of my original resources. I just dont like the look of MV faces and sprites, lol. Guess I will have make my own art.
I'm posting a commission art soon! :kaoswt2:

Forum statistics

Threads
107,458
Messages
1,029,839
Members
139,588
Latest member
HerlinFirehand
Top