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

2011/12/4

Need quick help with my code for new level

raniye raniye

2011/12/4

#
I want my Actor 'haai' to proceed to the next level 'level2' when my 'haai' is at the coordinates of 56, 30. But I don't know how to translate this into code. Here is my code for proceeding to the next level: private void checkNextLevel() { if (haai(57,30)) // Here is the fault, and I think here should come to code for my 'haai' to be at that place and then proceed. { if (level == 1) { level = 2; getWorld().removeObject(this); Greenfoot.setWorld(new level2(this)); } else { level = 1; getWorld().removeObject(this); Greenfoot.setWorld(new wereld(this)); } } }
bourne bourne

2011/12/4

#
If "haai" is an Actor, it contains getX() and getY() methods. So a condition should check if these produce the given coordinates.
raniye raniye

2011/12/4

#
Could you give an example? I'm afraid I don't understand it. Or just apply it to my code?
bourne bourne

2011/12/4

#
To invoke a method, you would do something like this haai.getX() That returns a number (its x coordinate). So then we can check if it is a 57. haai.getX() == 57 Same with the getY() method haai.getY() == 30 Put it together and we get if (haai.getX() == 57 && haai.getY() == 30)
raniye raniye

2011/12/4

#
Thanks, I tried it but I get an error: non-static method getX() cannot be referenced from a static context.
raniye raniye

2011/12/4

#
You can see my full game here: http://www.hairos.be/greenfoot/GameSOFO.zip Maybe this can help you
bourne bourne

2011/12/4

#
Okay, more context would be helpful. Is "haai" a class? And if so is private void checkNextLevel() within it? If that's the case, 1. class names should be capitalized. 2. you would just need to call the getX() and getY() without any reference to "haai" since you would be within an object of type "haai" So you would just need if (getX() == 57 && getY() == 30)
raniye raniye

2011/12/4

#
Well I've tried this, he didn't gave any errors but when I ran to that point with coordinates 56, 30 it opened an the Greenfoot: Terminal Window. So it still doesn't work.
Builderboy2005 Builderboy2005

2011/12/4

#
It would be helpful if you posted the exact errors that occurred. Also, is haai the name of the Class, or the name of the instance? Is the code you posted part of your haai Actor or part of the world?
raniye raniye

2011/12/4

#
Code is part of the haai Actor, but if you want the full game you can download it here : http://www.hairos.be/greenfoot/GameSOFO.zip
Builderboy2005 Builderboy2005

2011/12/4

#
Could you upload the code on the gallery? For some reason or another the code you posted opens in Greenfoot, but refuses to compile even if there are no Syntax errors.
kiarocks kiarocks

2011/12/4

#
@raniye, permission to upload the fixed version of the scenario? I have comments explaining what I did.
raniye raniye

2011/12/4

#
Yes you can upload it :-)
kiarocks kiarocks

2011/12/5

#
This should solve the problems on both the threads you started. Here it is.(Click this)
You need to login to post a reply.