I am making a game where there are different upgrades for certain traits of my character. I have a class called UpgradeBar that switches images after every upgrade. It works fine until you switch worlds and then come back. the data isn't saved! I made a non_actor class called DATA which will store ever variable for the upgrades. I made a new instance of the DATA in my world, but when I call getWorld().data.blahmethod(), it cannot find data. Here is the code where I try to call data:
I realize that this won't actually do anything yet but I need to be able to access the variable before I do anything else.
Thanks for any help!
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class UpgradeBar extends SUPERCLASS
{
public int upNum;
public int theNum;
String[] images = {"Upgrade0", "Upgrade1", "Upgrade2", "Upgrade3", "Upgrade4", "Upgrade5"};
public UpgradeBar(int partheNum){
theNum = partheNum;
}
public void act()
{
setImage();
}
public void setImage(){
setImage(images[upNum]+".png");
}
public void Upgrade(){
if(upNum < 5){
}
}
public void chooser(){
switch(theNum){
case 1: upNum = getWorld().data.getArmor();
break;
case 2: upNum = getWorld().data.getGunLevel();
break;
case 3: upNum = getWorld().data.getAmmoCapacity();
break;
case 4: upNum = getWorld().data.getMinigun();
break;
case 5: upNum = getWorld().data.getShotgun();
break;
case 6: upNum = getWorld().data.getCanon();
break;
case 7: upNum = getWorld().data.getMissile();
break;
case 8: upNum = getWorld().data.getMortar();
break;
case 9: upNum = getWorld().data.getRaygun();
break;
default: upNum = 0;
break;
}
}
}

