Im trying to do this Snakes and ladders type board game and Im trying to get a dice that generates a number and says "(player1) rolled = (random number)"
Theres another world that is like a name choosing menu (changename) where I put a string, String name1 = "default name"
The player supposedly chooses a name if they want and the name will appear with the value of the dice rolled.
The dice is in another world which is the game.
This is a function in the changename world
This code works in the 'changename' world however when I use getName1() in the 'game' world it says
java.lang.ClassCastException: game cannot be cast to changename
at dice.act(dice.java:17)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
No clue what ive done wrong.
public String getName1() { return name1; } public void setName1(String x) { name1 = x; }
public void act() { // Add your action code here changename worldref1 = (changename) getWorld(); String Name1 = worldref1.getName1(); }