Help, i cant reference my vars!

Posted by SystemNetworks on Game Development See other posts from Game Development or by SystemNetworks
Published on 2012-10-06T13:20:27Z Indexed on 2012/10/06 15:53 UTC
Read the original article Hit count: 330

Filed under:
|

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

Code:

s = new sub();

Then I put my sub function at the update method.

Code:

s.myFunc();

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:

Code:

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.
        if(wood>=200)
        {

            //Enter Store!
            if(input1.isKeyDown(Input.KEY_Q))
            {
                //Player must be in this cord!
                if((probePositionX>393 && probePositionX<555) && (probePositionY< 271 && probePositionY>171))
                {
                //The Store is On
                StoreOn=true;
                }
            }


        }



    }

}

In my main (update function) I put:

Code:

s.darkBought = darkBought;
s.darkEnergy = darkEnergy;
s.lifeLeft = lifeLeft;
s.money = 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???

© Game Development or respective owner

Related posts about java

Related posts about slick