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

2012/12/1

Need Some Help

ddavid33 ddavid33

2012/12/1

#
Hi guys quick question, i have a scenario where i have to make an actor pick up and drop an object, is there a code that i can use so that when a key "space" is pressed, it will pick up the object and when it is pressed again it drops the object? thanks in advance for the help and advise David
vonmeth vonmeth

2012/12/2

#
There is a book scenario you can take a look at that already has some code like this called "greeps" (removing object, check if object is near, changing image.) Basic way to do this. If "picker" is at "object" and hits space and "picker" is not already "carrying picker" then remove "object", change image of "picker" to "carrying picker." If "carrying picker" hits space, create "object" at the location of the "carrying picker", and change the image of "carrying picker" to "picker." You'll be using code like: getOneIntersectingObject Greenfoot.isKeyDown removeObject addObject Hope that helps!
danpost danpost

2012/12/2

#
@vonmeth, I think in this instance it might be better to use 'Greenfoot.getKey' instead of 'Greenfoot.isKeyDown'. As an alternative, a flag could be added to indicate that a dropped object cannot be picked up until the actor no longer intersects it or, better yet, to indicate that the space key is down and no further action can be done until it is released; something to prevent the 'picker' from picking up and dropping the object repeatedly. Using the last suggestion adds to option of performing the action (picking up or dropping of the object) on either the key press or the key release.
ddavid33 ddavid33

2012/12/2

#
hey guys, thanks for the fast responses, im not very good at this coding stuff, so could do with all the help possible. do any of you 2 have personal emails that i could have so that i could send you the scenarios so that we could work on it together. Thanks David
actinium actinium

2012/12/2

#
people usually say what they want to do then post the scenario + code to this site, no need for e-mails until you gain the trust of people.
tylers tylers

2012/12/2

#
ddavid33 ill do it :> tsimmonds278@gmail.com
ddavid33 ddavid33

2012/12/2

#
@actinium, i have no problem posting up the code, its not like i want to make this game private or anything, but having someone look at the code on their computer and also testing and giving me feedback would also help me understand what ive done wrong, if you get what i mean @tylers, thank you, i will send you what my scenario looks like now. thanks again guys
tylers tylers

2012/12/2

#
k
actinium actinium

2012/12/2

#
Well tyler trusts you and thats ok. Just saying when you upload a scenario with the code anyone can dig in and give you feed back. If you want to have feed back in private by e-mail then thats up to you. Good luck :-)
You need to login to post a reply.