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

2015/9/3

Getting a variable

DogeOverlord DogeOverlord

2015/9/3

#
So I'm having a bit of trouble getting a variable from another object.
private Actor Here;

Here = getOneObjectAtOffset(0,0,BeenHere.class);
        if(Here != null)
        {
            if(Here.index != world.index)
            {
                delete = true;
            }
        }
It cannot find the variable index from the BeenHere, which is a public int. I cannot make it static because there will be multiple BeenHeres.
danpost danpost

2015/9/3

#
Your 'Here' field is declared to hold an Actor object, not a BeenHere object. The compiler does not know to look in the BeenHere class for the 'index' field. Change line 6 to:
if (((BeenHere)Here).index != world.index)
As an alternative you could have the field declared as a BeenHere type field an adjust line 3 with the following:
private BeenHere Here;

Here = (BeenHere)getOneObjectAtOffset(0, 0, BeenHere.class);
Notice that casting the type of the returned actor object from using 'getOneObjectAtOffset' is required -- one way or the other.
You need to login to post a reply.