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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:44:32+00:00 2026-05-31T09:44:32+00:00

I have a problem with my arrays. I create them (which I’m not sure

  • 0

I have a problem with my arrays. I create them (which I’m not sure is correctly designed) but having difficulty understanding how to do checks on it.

My array is created like this:

id              = i++;
uid             = my_id;
imgwidth        = img[0].width;
imgheight       = img[0].height;
spritea[uid]    = new Array();
spritea[uid][0] = abposx;
spritea[uid][1] = abposy;
spritea[uid][2] = imgwidth;
spritea[uid][3] = imgheight;

I’m only assuming this is the correct way to store information about an image’s position and give it a unique id.

I then want to do checks on the follow example criteria:

if (x > spritea[0] && x < spritea[0]+spritea[2]){
    var uid = //get the UID of the array ;
}

But i think i have structured my array wrong? Any advice?

  • 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-31T09:44:33+00:00Added an answer on May 31, 2026 at 9:44 am

    Use an object. It’s cleaner:

    function create_image(id) {
        this.id = id;
        this.height = 0;
        this.width = 0;
        this.x = 0;
        this.y = 0;
    }
    
    my_image = create_image(++i);
    my_image.width = img[0].width;
    my_image.height = img[0].height;
    my_image.x = abposx;
    my_image.y = abposy;​
    

    For searching, try this:

    found_image = false;
    
    for (var i = 0; i < spritea.length; i++) {
      if (spritea[i].width == 4) {
        found_image = spritea[i];
        break;
      }
    }
    
    if (found_image) {
      // found_image is your image
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when using cell arrays in an m-file. I create a
I have a problem using JSON and arrays. Here is my code: while($row =
I’m working on a multi dimensions array but i have a problem Imagine I
I have got a strange problem about in_array recently which I cannot understand. e.g.
Well, I have a problem (ok, no real problem, but I wanna try out
I have created a script which is surprisingly working. (I do not do much
I have a little problem, I don't know how to create the script (with
It's weird because I have done it before but it just is not working.
Lets say i have an array of arrays, of which i dont know the
So recently I was given a problem, which I have been mulling over and

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.