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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:48:44+00:00 2026-05-27T13:48:44+00:00

I have two scenes. Scene A is the game scene, where the level variable

  • 0

I have two scenes. Scene A is the game scene, where the level variable of type int changes. In class B I want to get the variable.

What I’ve got now is the following :

——————————— LevelDone.m ———————————

HelloWorldLayer *object = [[HelloWorldLayer alloc]init];

        int pointsForZeroStars = [[requiredPoints objectAtIndex:0] integerValue];
        int pointsForOneStar = [[requiredPoints objectAtIndex:1] integerValue];
        int pointsForTwoStars = [[requiredPoints objectAtIndex:2] integerValue];
        int pointsForThreeStars = [[requiredPoints objectAtIndex:3] integerValue];
        NSLog(@"HEALTH = %d",object.health);
        CCSprite *levelDoneWindow;         
        if ( object.health < pointsForZeroStars){
            NSLog(@"should be 0 stars");
            levelDoneWindow = [CCSprite spriteWithFile:@"leveldonescreen0stars.png"];
        }

NSLog returns the initial value of health which is 100, when actually it is something smaller than 100.

In the game class I call pushscene in order to call the LevelDone scene:

—————————– HelloWorldLayer.m (GAME SCENE) ————————————-

else{

    [[CCDirector sharedDirector] pushScene:[LevelDone node]];
    [self generateLevelFromPlist:level];


}

The -generateFromPlist method resets the health to 100. But it is certainly called after the NSLog method in my LevelDone.m class, which nonetheless prints out that health is 100.

How do I retrieve the value of this variable properly ?

  • 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-27T13:48:44+00:00Added an answer on May 27, 2026 at 1:48 pm

    Use a singleton to manage global values.

    http://getsetgames.com/2009/08/30/the-objective-c-singleton/

    Basically, you can create properties in that singleton class, and it will “persist” throughout the game no matter what scene you are in etc.

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

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have an iOS 5 application with a storyboard and two scenes. Scene 1
I have two scene in my flash file , and I want to move
Ok I have two classes: Image and Scene. Now in the Image header file,
I have two canvas's in a Grid, full scene images that I want to
I have a scene(view) where I want to divide it in two parts like
I am rendering a scene in which I have two spheres. I am revolving
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two spreadsheets... when one gets modified in a certain way I want
In my cocos2d project, I have two scenes. I transition between the two using

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.