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

  • Home
  • SEARCH
  • 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 715491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:11:35+00:00 2026-05-14T05:11:35+00:00

I am trying to code a global lookup table of sorts. I have game

  • 0

I am trying to code a global lookup table of sorts.

I have game data that is stored in character/string format in a plist, but which needs to be in integer/id format when it is loaded.

For instance, in the level data file, a “p” means player. In the game code a player is represented as the integer 1. This let’s me do some bitwise operations, etc. I am simplifying greatly here, but trying to get the point across. Also, there is a conversion to coordinates for the sprite on a sprite sheet.

Right now this string->integer, integer->string, integer->coordinate, etc. conversion is taking place in several places in code using a case statement. This stinks, of course, and I would rather do it with a dictionary lookup.

I created a class called levelInfo, and want to define the dictionary for this conversion, and then class methods to call when I need to do a conversion, or otherwise deal with level data.

NSString *levelObjects = @"empty,player,object,thing,doohickey";
int levelIDs[] = [0,1,2,4,8];
// etc etc

@implementation LevelInfo

+(int) crateIDfromChar: (char) crateChar {
    int idx = [[crateTypes componentsSeparatedByString:@","] indexOfObject: crateChar];
    return levelIDs[idx];
}

+(NSString *) crateStringFromID: (int) crateID {
    return [[crateTypes componentsSeparatedByString:@","] objectAtIndex: crateID];
}

@end

Is there a better way to do this? It feels wrong to basically build these temporary arrays, or dictionaries, or whatever for each call to do this translation. And I don’t know of a way to declare a constant NSArray or NSDictionary.

Please, tell me a better way….

  • 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-14T05:11:36+00:00Added an answer on May 14, 2026 at 5:11 am

    If you want an array to be available to all the code in your class, just declare it outside the @implementation context, and then initialize it in your class’s +initialize method.

    NSArray *levelObjects;
    
    @implementation LevelInfo
    
    + (void) initialize
     {
     if (!levelObjects)
       levelObjects = [[NSArray alloc]
        initWithObjects:@"empty",@"player",@"object",@"thing",@"doohickey",nil];
     }
    
    // now any other code in this file can use "levelObjects"
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the Global Interface Table by using the following code (Delphi):
I´m trying to code a tooltip (Yes I know, I have my reasons to
I am trying to code an application that monitors sms messages. I want to
I'm trying to handle errors that have occurred on other threads the .NET CF
I am trying to write code that will loop through all cells in a
virI'm trying to create a lookup table in my ASP.NET MVC4 application with Entity
I am trying to migrate my project code from OSCache to EhCache. We have
I am trying to make code that will retrieve courses, instructors and times from
I am having below html code and trying to add new values to global
I have sharepoint site and i want read in code global navigation information. On

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.