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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:13:35+00:00 2026-05-17T22:13:35+00:00

I have a game which have 5 class/level.Each class contain almost same variables.Now i

  • 0

I have a game which have 5 class/level.Each class contain almost same variables.Now i want to know in which place should i declare my class variable.I have three option-

1.declaring the class variable in corresponding class .h file.
2.declaring a variable .h file(an empty .h file only for declaring variable and then import it to corresponding class.m file).
3.declaring the class variable in class .m file before init method.

Now I want to know which is the correct method.

**each class must import other class .h file because after completing level-1 i have to go level-2.So for scene transition i have to import level-2.h file and so on.

And one fore things if i import a class.h file which has same class variable like my class file ,then is it conflict with my class variable, or what will happen??

  • 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-17T22:13:35+00:00Added an answer on May 17, 2026 at 10:13 pm

    To answer your question: “if i import a class.h file which has same class variable like my class file ,then is it conflict with my class variable, or what will happen??”

    No there will not be a conflict. When you define instance variables in a class, it is for objects of that class type only. For example, if you have Class1 which has a property UIColor *color and Class2 has a property UIColor *color, and you include the Class2.h file in class1.m, then you do something like color = [UIColor blueColor]; in a method inside Class1.m you will be referring to class1’s color property. To refer to the color property of class2, you would have to instantiate a class2 object and then set it’s property like so:

    Class2 *c2 = [[Class2 alloc] init];
    c2.color = [UIColor greenColor];
    

    Hope that helps a little.


    Also, as others have mentioned, you should really just have one game class and either create new instances of the same class or just change the properties of the existing instance. If the 5 classes are very similar, but just harder, you should just have a difficulty property, and then use new instances of the same class with that property set to a higher value.

    And, to clear any confusion, let’s say you have Class1 again and it’s a view controller. You can, inside a method in Class1, create a new Class1 object and display it and it will be a new instance of Class1, with whatever different properties you set.

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

Sidebar

Related Questions

I have, for my game, a Packet class, which represents network packet and consists
I have a game in which you can score from -40 to +40 on
How can I have that functionality in my game through which the players can
I have an game application I have written for Windows Mobile and I want
I have a little game written in C#. It uses a database as back-end.
I have written a game that uses GLUT, OpenGL and FMOD. The problem is
I have my own game engine using C++ and OpenGL, but I have models
I have little knowledge of Flash but for a little Flash game I have
Ok guys just a small game: I have some specifications for a project. At
I have an OpenGL ES game that I am hacking together. One part 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.