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

2017/5/25

objectsatoffset -> return??

LegendofLife LegendofLife

2017/5/25

#
Hallo community, I want to programm Pacman, but now I have a problem: I need a command, which can check if there is object (Wand.class) at a specific pixel (X/Y). I think Objectsatoffset(); should work, but I don´t know how to check if it´s Wand.class or how convert that signal if it´s true or false into a boolean.
getObjectsAtOffset(3,0,Wand.class);
I hope you understood my problem. Have a nice day.
Trystar360 Trystar360

2017/5/25

#
try replace name with whatever you'd like
public boolean name(int x, int y, java.lang.Class clss))
{
      boolean a = false;
      if(getOneObjectAtOffset( x,y,clss) != null)
      a = true
      else a = false;
      return a;
}
then you'd do like
 if (name(3,0,Wand.class) == true)
{
        //your action
}
Trystar360 Trystar360

2017/5/25

#
Like you could have a boolean atLocation like
public boolean atLocation;
then do
if(name(3,0,Wand.class) == true)
atLocation = true;
else
atLocation = false;
danpost danpost

2017/5/25

#
To check if 'getOneObjectAtOffset' returns Wand object or not:
if (getOneObjectAtOffset(3, 0, Wand.class) != null)
If no wand is detected at the location, a 'null' value is returned.
LegendofLife LegendofLife

2017/5/25

#
Trystar360 wrote...
Like you could have a boolean atLocation like
public boolean atLocation;
then do
if(name(3,0,Wand.class) == true)
atLocation = true;
else
atLocation = false;
If I do it like this "name" gets red underlined, with the tip "cannot find symbol - ..." now i just hab the idea to replace "name" with "getOneObjectAtOffset" but it doesn´t work aswell The other solutions i didn´t got... I´m still learning Greenfoot
if(getOneObjectAtOffset(3,0,Wand.class) == true)
            {    
                atLocation = true;
                NachOben = true;
            }
            else
            {    
                atLocation = false;
                NachOben = false;
            }
LegendofLife LegendofLife

2017/5/25

#
@danpost how to use that "null"
danpost danpost

2017/5/25

#
LegendofLife wrote...
how to use that "null"
Just as given
if (getOneObjectAtOffset(3, 0, Wand.class) != null)
If no wand is detected at the location, a 'null' value is returned.
You need to login to post a reply.