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

2019/1/26

How can you keep variables between worlds

1
2
iminblue iminblue

2019/2/2

#
Ok so I just now got to work on adding the player in another world using your method and I get this error non-static method addPlayer(Player) cannot be refrenced from a static context . What does it mean ?
danpost danpost

2019/2/2

#
iminblue wrote...
Ok so I just now got to work on adding the player in another world using your method and I get this error non-static method addPlayer(Player) cannot be refrenced from a static context . What does it mean ?
It means you are trying to call the method using the class name instead of using an object created from the class.
iminblue iminblue

2019/2/2

#
danpost wrote...
iminblue wrote...
Ok so I just now got to work on adding the player in another world using your method and I get this error non-static method addPlayer(Player) cannot be refrenced from a static context . What does it mean ?
It means you are trying to call the method using the class name instead of using an object created from the class.
Ok , and how do I solve the problem? I don't reallt understand how to create an object inside the class.
danpost danpost

2019/2/3

#
iminblue wrote...
Ok , and how do I solve the problem? I don't reallt understand how to create an object inside the class.
In which class is the addPlayer(Player) method located? and which class, and where in the class, are you trying to call it from?
iminblue iminblue

2019/2/3

#
danpost wrote...
iminblue wrote...
Ok , and how do I solve the problem? I don't reallt understand how to create an object inside the class.
In which class is the addPlayer(Player) method located? and which class, and where in the class, are you trying to call it from?
I did it just as you said : addPlayer is in the World's code , and I try to call it from a method inside the Player class :
public void enterDoor()
    {yeet2 w2 = new yeet2();
        yeet2.addPlayer();
        Greenfoot.setWorld(w2);
    }
Using this directly in the act() method doesn't work either.
danpost danpost

2019/2/3

#
iminblue wrote...
I did it just as you said : addPlayer is in the World's code , and I try to call it from a method inside the Player class : << Code Omitted >> Using this directly in the act() method doesn't work either.
In line 3, you are trying to call addPlayer on an object of type Class (called yeet2). This will not work -- you cannot add a player to a class; you can only add a player to an object of type World (or, in your case, specifically, a yeet2 world instance). You create one on line 2 and name it w2. That is what you need to call the method on.
iminblue iminblue

2019/2/3

#
danpost wrote...
iminblue wrote...
I did it just as you said : addPlayer is in the World's code , and I try to call it from a method inside the Player class : << Code Omitted >> Using this directly in the act() method doesn't work either.
In line 3, you are trying to call addPlayer on an object of type Class (called yeet2). This will not work -- you cannot add a player to a class; you can only add a player to an object of type World (or, in your case, specifically, a yeet2 world instance). You create one on line 2 and name it w2. That is what you need to call the method on.
Oh God right it was so easy why did I get confused like that ??
You need to login to post a reply.
1
2