Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5971951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:35:22+00:00 2026-05-22T20:35:22+00:00

I have an object called TruckModel which is defined earlier in my JavaScript file

  • 0

I have an object called TruckModel which is defined earlier in my JavaScript file called milktruck.js

I’m trying to create an array of these TruckModel objects because I don’t know at any given time how many TruckModel objects will be needed as players of my multiplayer game enter and exit.

I know that my current code isn’t working because the model won’t display when I use the teleportToThat function below.

I was able to get the model to display by declaring only one TruckModel() object in my index.html file and then using the teleportToThat

Here’s my code for this, do you see any errors in how I’m doing it?

Non-working version:

 var opponentTrucks = [];

 for (var i = 0; i < markers.length; i++) {

      opponentTrucks[i] = new TruckModel();
      opponentTrucks[i].teleportToThat( lat, lng, heading );

 }

Working version: (Difference being that I’m trying to have a varying amount of TruckModel objects)

Declared in index.html file:

 var model;

Declared in JavaScript file:

 model.teleportToThat( lat, lng, heading );

Here’s the entire JavaScript file:

http://thehobbit2movie.com/milktruck.js

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:35:23+00:00Added an answer on May 22, 2026 at 8:35 pm

    If you want to be able to find the objects by numeric index, you want an array, not a plain object:

    var opponentTrucks = [];
    

    What you’ve got will work, kind-of, but there’s no reason not to use a real array if you’re going to treat it like one anyway.

    edit — it’s still not really clear exactly what the problem is. This line here:

    opponentTrucks[i].teleportToThat( lat, lng, heading );
    

    What is that supposed to do? Where is it called from? What’s the value of “i”? If you simply have that statement following the loop, then it’s not going to work. If you want to have that “teleportToThat()” function called for each one in the array, then you should put the function call inside the “for” loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object called Review which :belongs_to two objects: Users and Vendors. In
Say I have an object called MyClass, which has a property defined as @property
I have an object class called BOM. It has a method, getChildItem() which returns
I have an NSDate object called 'dueDate'. I'm trying to work out how to
I have a collection of an object called Bookmarks which is made up of
I have a c# object with a property called Gender which is declared as
I have object called Foo. Right now it implements IFoo which has a lot
I have an object called EmailMessage, which has a nullable System.DateTime field called Timestamp.
I have an object called SampleObject that holds an array of strings called StringArray.
I have a method called xyz which returns an object. private XYZ xyz() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.