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 6926881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:58:32+00:00 2026-05-27T10:58:32+00:00

I’m writing a game that involves cargo, and I plan to have a large

  • 0

I’m writing a game that involves cargo, and I plan to have a large number of cargo types. Currently I have a Cargo class, and a ship carrying cargo has an array of the Cargos it is holding.

I’d really rather not have each ship with a bunch of objects when all I really want to know is how much of which cargoes each ship has. Especially when these ships will be created and discarded a lot.

I’m sure the thing I’m looking for is so basic I’ll look dumb for even asking, but I know there’s something similar to an array that holds an object and a related value. I want to use that to reference the Cargo type from the static array, and hold the quantity.

What’s it called? How would I use it (ie what are common functions used for it)? Some code snippets and terminology would be ideal.

  • 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-27T10:58:32+00:00Added an answer on May 27, 2026 at 10:58 am

    You are probably looking for the Dictionary class. It’s similar to arrays (which use integer indexes) or objects (which can be used as string based, associative arrays). A Dictionary uses objects as unique keys that get mapped to a single value.

    I think you don’t need one though. A global variable is rarely a good idea. I wouldn’t unnecessarily complicate this and just let each ship handle it’s own cargo, maybe by using a quantity as AaronLS suggested. But don’t worry too much about performance here, even if you create and destroy thousands of ships each frame, rendering them will take significantly more time than the handling of arrays.

    Anyway, here’s how you use a dictionary and some things to consider. It doesn’t have much special methods, it’s used almost like an array.

    var dict = new Dictionary();
    var key:MyClass = new MyClass(); // a key can be of any class 
    
    dict[key] = "foo"; // set a value
    trace( dict[key] ); // traces: foo
    
    dict[key] = null; // set value to null, key is still there. It won't get garbage collected!
    delete dict[key]; // remove the key
    

    Consider using new Dictionary(true) to avoid the garbage collection issue.

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.