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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:02:02+00:00 2026-06-04T13:02:02+00:00

I have some game data in my GameStateSingleton , which I don’t want to

  • 0

I have some game data in my GameStateSingleton, which I don’t want to retrieve every time explicitly with [[GameStateSingleton sharedMySingleton]getVariable], so I asked myself whether it is possible to do something like that :

In the interface file of my class, GameLayer I set up properties and variables like sharedHealth.

@interface GameLayer : CCLayer
{
    int sharedHealth;

}
@property (nonatomic,assign) int sharedHealth; 

and of course synthesize it in the implementation.

@synthesize sharedHealth;

In the initialization of GameLayer I would like to do something like :

sharedHealth = [self getCurrentHealth];

and add the corresponding method

-(int)getCurrentHealth{
   int myHealth = [[GameStateSingleton sharedMySingleton]getSharedHealth];
   return myHealth;
}

Is that possible ? From what I have experienced, I just seem to get crashes. How would I achieve my goal, to not always have to call the long method, as it always retrieves the same variable? There has to be a solution for this …

  • 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-04T13:02:05+00:00Added an answer on June 4, 2026 at 1:02 pm

    You don’t need an instance variable for that. You could just write a shortcut function like this:

    - (int)sharedHealth {
        return [[GameStateSingleton sharedMySingleton] getSharedHealth];
    }
    

    And where ever you need that value, you call [self sharedHealth].

    You could also use a preprocessor macro instead. Just define this:

    #define SharedHealth [[GameStateSingleton sharedMySingleton] getSharedHealth]
    

    And then simply use that when you need the value.

    Note, that in Objective-C you don’t call getter methods “getVariable“, but simply “variable“. Mostly this is a convention, but if you start using KVC or KVO it’s a rule you have to follow. So it’s better to get used to it as soon as possible.

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

Sidebar

Related Questions

Say I have some data which I want several kinds of. I think the
I'm trying to start my java game but I have some troubles with the
OK so I am working on some game logic, I have done a fair
I'm working on a simple board game in qt, and i have some problem
I have this game with some variety of textures. Whenever I draw a texture
I am creating a small Yahtzee game and i have run into some regex
I have a game service, some of my gamerooms are password protected. In the
I think some of you have seen the cartoon wars game. does anybody know
I have a game loop written in Haxe/Flash. For some reason it slows down
I have small game engine written in c++. I'm considering using some features of

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.