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

2012/3/13

How can you add a new actor to the world with specific variables?

IsaacIIV IsaacIIV

2012/3/13

#
i want to add a new version of my actor to the world with specific variables which can change depending on where the method is called. I tried ... Actor temp = new Tower(); getWorld().addObject(temp,50,50); temp.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200); and in the Tower actor - String image = ""; String ammo = ""; int rate = 0; int range = 0; int splash = 0; int type = 0; int price = 0; public void get(String im,String am,int rt,int rg,int sp,int tp,int pr) { image = im; ammo=am; rate=rt; range=rg; splash = sp; type =tp; price = pr; } That didn't work. can someone please tell me how to do this?
davmac davmac

2012/3/13

#
Change: Actor temp = new Tower(); To: Tower temp = new Tower(); Because the get(...) method is defined for the Tower class, you need a reference of type Tower to call it.
IsaacIIV IsaacIIV

2012/3/13

#
How do i call the method then because both... Tower temp = new Tower(); getWorld().addObject(temp,50,50); temp.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200); and.. Tower temp = new Tower(); getWorld().addObject(temp,50,50); Tower.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200); dont work??
danpost danpost

2012/3/13

#
I think you mis-understood. Try: Tower temp = new Tower(); getWorld().addObject(temp,50,50); temp.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200);
davmac davmac

2012/3/13

#
I can 't see why this wouldn't work:
Tower temp = new Tower(); 
getWorld().addObject(temp,50,50);
temp.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200);
What is the error message you get, and on what line?
IsaacIIV IsaacIIV

2012/3/13

#
ohh i see i was still putting temp().get.. Tower temp = new Tower(); getWorld().addObject(temp,50,50); temp.get("TW-CRT.png","AM-CRT.png",5,30,1,1,200); working great :) thank you
You need to login to post a reply.