This site requires JavaScript, please enable it in your browser!
Greenfoot back
8bitorangejuice
8bitorangejuice wrote ...

2013/6/27

static int: How do I change it from a subclass?

8bitorangejuice 8bitorangejuice

2013/6/27

#
Hello there, I need help changing the int rn from my subclass 'Groundside'; here are my classes(Placer, Ground & Groundside). Placer:
public class Placer extends GifActor
{
    static int rn;
    static int gsy;
    static boolean rnc;
    
static boolean getRNC()  
{  
    return rnc;  
}  
static void setRNC(boolean type)  
{  
    rnc = true;  
}  
public void act() 
{          
}
}
Ground:
public class Ground extends Placer
{
    boolean costume;
    boolean random=false;

public void addedToWorld(World world)  
{
        gsy= getY();
        setImage("building2.gif"); 
}
    public void act() 
{
        super.act();
    setLocation(getX() - 4, getY());
        boolean random=false;
    {
      rn=Greenfoot.getRandomNumber(300)+200;
        {
        if (getX()<10)
        {           
            setLocation(590,rn);
            rnc=false;
        }
        if(getX()>10)
        {
            rnc=true;
        }
        if (getY()>275)
        {
            setImage("building2.gif");
        }
        else if(getY()<275)
        {
            setImage("building1.gif");
        }
        if(getY()<275)
        {
            setLocation(getX(),270);
        }
    }
}
}}
and finally, Groundside:
public class Groundside extends Placer
{

public void addedToWorld(World world)  
{

}
static boolean getRNC()  
{  
    return rnc;  
}  
public void act() 
{
        setLocation(getX() - 4, getY());
        boolean random=false;           
{
        {
        if (random=true&&rn<200)
        {
            random = false;
        }
        if (getX()<10)
        {
            setLocation(590,rn);
            random=true;
        }

}
}}}
I am trying to change the static int 'rn' from the subclass 'Groundside'
Gevater_Tod4711 Gevater_Tod4711

2013/6/27

#
Could you be more specific? What exactly is the problem?
Zamoht Zamoht

2013/6/27

#
You could try make it public, but if that doesn't work you should make a public set method in the super class.
davmac davmac

2013/6/27

#
Either use 'Placer.rn = (value);' or declare rn to be either protected or public (in the Placer class) and then just use 'rn = (value);'.
8bitorangejuice 8bitorangejuice

2013/7/1

#
Thanks!
You need to login to post a reply.