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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 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 ; } } } |