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

2012/4/13

getInfo from ofther Actor

PStigerID PStigerID

2012/4/13

#
Last one for today. Thank you to all of those who really help me here!! this works (as long as I am in L1):
            L1 w = (L1) getWorld();      
            mouse m = w.getMouse();
            int x = m.getX();
            int y = m.getY();
            int r = m.getRotation();
L1=World mouse=Actor getMouse - in Level
public L1()
   {
        [...]
        theMouse = new mouse();
        addObject(theMouse,100,300);
    }
public mouse getMouse()
    {
        return theMouse;
    }
Now I can work with those ints. Now I want to change the world - so I need to change the code. Could I do this with a void? I tried it with
   World(getWorld());
---------------------------------------
    private void World(string X){
            X w = (X) getWorld();      
            mouse m = w.getMouse();}
but this did not work (as expected). Is there an easier way to do it? (I would rather have a void than if(World ==) - becuase I have alot of world currently. A other question: As far as I can see in the documentation getWorld() returns the current world. Is this correct? Thanks PStiger
danpost danpost

2012/4/14

#
One thing, is you are trying to call 'World(string X)' with 'World(getWorld())' (sending a World object to a method that receives a String object ). Then, you are taking that, supposed, string object and trying to use it as a class name. If you are trying to get 'mouse' infomation from whatever world it is in, you may have to
World w = getWorld();
if (w instanceOf L1) (L1) w;
if (w instanceOf X) (x) w;
// etc.
casting what was returned from getWorld() to the proper sub-class of world before you can access that information.
You need to login to post a reply.