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

2021/11/4

getWorld().addObject isnt working

Sombra Sombra

2021/11/4

#
It keeps saying at the start of getWorld().addObject '(' or'public class test_tower_icon extends Actor { /** * Act - do whatever the test_tower_icon wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(!Greenfoot.mousePressed(null)) { test_tower_state_placement test_tower_state_placement = new test_tower_state_placement getWorld().addObject(new test_tower_state_placement(), getX(), getY()); } } }
danpost danpost

2021/11/4

#
Sombra wrote...
It keeps saying at the start of getWorld().addObject '(' or 'open square bracket' expected.
The previous line is incomplete. It needs '();' to finish it off. However, the act method will product one of those objects about 60 times a second continuously, provided the mouse is not pressed. I doubt that is what you want.
Sombra Sombra

2021/11/4

#
Thx a lot,and I appreciate seeing you in every post
danpost danpost

2021/11/4

#
Sombra wrote...
Thx a lot,and I appreciate seeing you in every post
Actually, you can completely remove the line that was incomplete since you create another object of that type to add to the world in the next line. The "problem" with the act method in general still would need resolved.
You need to login to post a reply.