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

2022/10/31

Sharing a value from variable between world

Baransu69 Baransu69

2022/10/31

#
Hi! can i share a value from variables between ? for example:
public class World1 extends World
{
    private int score;
}
to world2
Baransu69 Baransu69

2022/10/31

#
and it cant be static
Super_Hippo Super_Hippo

2022/11/1

#
Do you switch from one world to the other? If you then want to send something over, you could do this:
//in ‘World1’
World2 w2 = new World2();
w2.setScore(score);
Greenfoot.setWorld(w2);
//in ‘World2’ (or in ‘World’ if you also move ‘score’ there)
public void setScore(int newScore)
{
    score = newScore;
}
Baransu69 Baransu69

2022/11/2

#
dude tthnx , hope you have a good day
You need to login to post a reply.