In my JavaScript file, milktruck.js, I have defined an object called TruckModel.
My goal is to create an array of TruckModel objects because in my multiplayer game, I cannot predict how many players will enter or exit at any given time.
The issue I am facing is that the model is not displaying when I use the teleportToThat function below.
I managed to display the model by only declaring one TruckModel() object in my index.html file and using the teleportToThat function.
Can you review my code and point out any potential errors?
Here is the non-working version:
var opponentTrucks = [];
for (var i = 0; i < markers.length; i++) {
opponentTrucks[i] = new TruckModel();
opponentTrucks[i].teleportToThat(lat, lng, heading);
}
Here is the working version (where I am aiming to have varying amounts of TruckModel objects):
Declared in index.html file:
var model;
Declared in JavaScript file:
model.teleportToThat(lat, lng, heading);
Here is the complete JavaScript file: