PDA

View Full Version : Creating New Methods


timsally
12-20-2010, 09:46 PM
I have a question that will probably seem elementary, but I am a just beginning to learn the rules of programming.

I'm creating a world with three objects -- a frog, a bunny, and a hampster -- and they are interacting with each other.

My question relates to creating a new method that involves a single action by two of the objects, as seen here:

frog.head point at bunny.upperBody.head duration 0.5 seconds
hampster.head point at bunny.upperBody.head duration 0.5 seconds

Is creating new methods reserved for multiple actions of ONE object, or am I alright with combining the actions above for two objects into a method since they repeat?

Thanks,

Tim S.

arty-fishL
12-21-2010, 11:24 AM
You are alright with combining the actions above for two objects into a method since they repeat if you stick it in a world level method, in fact you should. An object level method should really be preserved for that object.

jediaction
03-30-2011, 10:48 AM
I have a question that will probably seem elementary, but I am a just beginning to learn the rules of programming.

I'm creating a world with three objects -- a frog, a bunny, and a hampster -- and they are interacting with each other.

My question relates to creating a new method that involves a single action by two of the objects, as seen here:

frog.head point at bunny.upperBody.head duration 0.5 seconds
hampster.head point at bunny.upperBody.head duration 0.5 seconds

Is creating new methods reserved for multiple actions of ONE object, or am I alright with combining the actions above for two objects into a method since they repeat?

Thanks,

Tim S.

Adding on to Arty, you can do multiple actions in any statement holder. Do together is good for that. You can do it with events. But its better to stick to Methods. You can make a method inside a method to. In the end. They all do the same thing and everyones happy!

kompsci
04-15-2011, 05:34 PM
imo, methods that deal with objects should be created for that object(really class i guess). so if your bunny turns his head, it should be a method for the bunny. since the bunny is doing it, it belongs with the bunny, not the world. so make a bunny turn method, and a hamster turn method, then call them within your main method that runs when the world starts. thats my opinion

reuben2011
04-15-2011, 05:50 PM
imo, methods that deal with objects should be created for that object(really class i guess). so if your bunny turns his head, it should be a method for the bunny. since the bunny is doing it, it belongs with the bunny, not the world. so make a bunny turn method, and a hamster turn method, then call them within your main method that runs when the world starts. thats my opinion

Or you could make a general world method named "turn" that accepts an object as a parameter. That would be more efficient if you have multiple objects that do the same or similar thing.

ebarrera
06-12-2011, 09:14 PM
I think you are right combining both in the same method. However, you can also make them work in separate methods.

jaxadams
07-07-2011, 04:24 PM
I agree either method would work well.