Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a sub-class(let's call it sub) and it contains all the function of an object in my game. In my main class(Let's call it main), i connect my sub to main. (Example sub


s = new sub();

Then I put my sub function at the update method.



Becuase in my sub, i have booleans, integers, float and more. The problem is that I don't want to connect my main class to use my main's int, booleans and others. If i connect it, it will have a stack overflow. This is what I put in my sub:


package javagame;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame;

public class Armory {
   package javagame;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.state.StateBasedGame;

public class Store {
    public Integer wood;
    public Float probePositionX;
    public Float probePositionY;
    public Boolean StoreOn;
    public Boolean darkBought;
    public Integer money;
    public Integer darkEnergy;
    public Integer lifeLeft;
    public Integer powerLeft;
    public void darkStores(GameContainer gc, StateBasedGame sbg, GameContainer gc2)
        Input input1 = gc.getInput();

        //Player need wood to enter(200) If not there will be an error.

            //Enter Store!
                //Player must be in this cord!
                if((probePositionX>393 && probePositionX<555) && (probePositionY< 271 && probePositionY>171))
                //The Store is On




In my main (update function) I put:


s.darkBought = darkBought;
s.darkEnergy = darkEnergy;
s.lifeLeft = lifeLeft; = money;
s.powerLeft = powerLeft;
s.probePositionX = probePositionX;
s.probePositionY = probePositionY;
s.StoreOn = StoreOn;
s.wood = wood;
s.darkStores(gc, sbg, gc);

The problem is when I go to the place, and I press q, nothing shows up. It should show another image. Is there anything wrong???

share|improve this question

closed as too localized by Byte56, Tetrad Oct 6 '12 at 17:01

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I'm not sure your listening. This is too localized question for this site. This is purely purely about java programming and not about game development. You should read about Java basics. But you don't really care do you? :-) – nathan Oct 6 '12 at 13:23
I edited your code to indent it properly. What's with the Armory thing? Bad copy/paste? Also it looks like you left the first line half finished. – doppelgreener Oct 6 '12 at 13:31
Aside: Your post is pretty vague. "Is there anything wrong?" Yes, clearly - it isn't showing up though you've attempted to program it as such. There could be any number of things wrong, we just can't tell you so from this code. Maybe the input doesn't work, or the coordinates don't work, or the drawing doesn't. – doppelgreener Oct 6 '12 at 13:35

This is off topic for the site so I hope it gets moved to Stack Overflow.

Your question isn't well written and I don't really understand it, but this does stand out to me: After pressing Q, you set StoreOn to true.

In your "update function" however, you say this:

s.StoreOn = StoreOn;

Where s.StoreOn is a completely different variable to StoreOn. I'm not even sure why you're setting it, but if StoreOn is false, you're constantly setting s.StoreOn to false, either in the very frame following you pressing Q, or before that frame is even over.

I'm not sure what you're doing and I'm not sure you're sure either. The language in your title ("Help, I can't reference my vars!") being completely weird and not making much sense in the context says a lot. After all, you can get at your variables just fine apparently, it's just that you've got weird behaviour, so I'm not sure what you mean and you're probably not sure either.

It seems you're out of your depth and you don't really understand what you're doing very well, so the best advice I can give you is go back and complete some basic tutorials on Java programming. It looks like you're struggling, and you're missing a lot of basics. You could really, really do with learning those basics, so go back to basics and learn them.

Do a tutorial.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.