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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:54:30+00:00 2026-06-08T20:54:30+00:00

I made an original post here At first, I tried to fill up a

  • 0

I made an original post here

At first, I tried to fill up a CGPoint **allPaths.

With the first dimension being “a path” and the second dimension being “the waypoint”. And I get a CGPoint out of this.

For example : allPaths[0][2] would give me the CGPoint of the first path, third waypoint.

I successfully did it in plain C with nasty loops. And now I am trying to do the same thing in Obj-C with NSMutableArrays.

Here is my code :

CCTMXObjectGroup *path;
NSMutableDictionary *waypoint;

int pathCounter = 0;
int waypointCounter = 0;

NSMutableArray *allPaths = [[NSMutableArray alloc] init];
NSMutableArray *allWaypointsForAPath = [[NSMutableArray alloc] init];

//Get all the Paths
while ((path = [self.tileMap objectGroupNamed:[NSString stringWithFormat:@"Path%d", pathCounter]]))
{
    waypointCounter = 0;
    //Empty all the data of the waypoints (so I can reuse it)
    [allWaypointsForAPath removeAllObjects];

    //Get all the waypoints from the path
    while ((waypoint = [path objectNamed:[NSString stringWithFormat:@"Wpt%d", waypointCounter]]))
    {
        int x = [[waypoint valueForKey:@"x"] intValue];
        int y = [[waypoint valueForKey:@"y"] intValue];

        [allWaypointsForAPath addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
        //Get to the next waypoint
        waypointCounter++;
    }

    //Add the waypoints of the path to the list of paths
    [allPaths addObject:allWaypointsForAPath];

    //Get to the next path
    pathCounter++;
}

My actual problem is that all paths in allPaths are equal to the last one. (all the first paths are overrided with the last one)

I know that it is because of this line [allPaths addObject:allWaypointsForAPath].

Yet, how should I do it ?

  • 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-06-08T20:54:32+00:00Added an answer on June 8, 2026 at 8:54 pm

    Oh I think I found out something !
    Not sure about memory issue, but I guess the garbage collector should work ?

    Actually, I just have to declaremy NSMutableArray *allWaypointsForAPath in the loop like this :

    int pathCounter = 0;
    int waypointCounter = 0;
    
    NSMutableArray *allPaths = [[NSMutableArray alloc] init];
    
    //Get all the PathZ
    while ((path = [self.tileMap objectGroupNamed:[NSString stringWithFormat:@"Path%d", pathCounter]]))
    {
        waypointCounter = 0;
        NSMutableArray *allWaypointsForAPath = [[NSMutableArray alloc] init];
        //Get all the waypoints from the path
        while ((waypoint = [path objectNamed:[NSString stringWithFormat:@"Wpt%d", waypointCounter]]))
        {
            int x = [[waypoint valueForKey:@"x"] intValue];
            int y = [[waypoint valueForKey:@"y"] intValue];
            [allWaypointsForAPath addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]];
            //Get to the next waypoint
            waypointCounter++;
        }
    
        [allPaths addObject:allWaypointsForAPath];
        //Get to the next path
        pathCounter++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made the mistake of modifying my original source after importing it into subversion.
I'm facing a huge problem here which is driving me crazy, I've made an
Original question has been answered. Update addresses related question raised in comments. Original post:
Ive made edits since the orignal post Im making an android app that connects
Edit: My original example had a silly mistake. After fixing it I still get
I am using jquery post, and somehow it seems the post get posted twice.
Made this nice little loop for hiding and showing div's, works as a charm
Made a custom obj called Item with some string fields and one float. .h
I made a dll in c# but i need to export the functions. Is
I made an iphone app to capture image from camera and to set that

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.