Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Reply
 
Thread Tools Display Modes
Creating New Methods
Old
timsally
Guest
 
Status:
Posts: n/a
Default Creating New Methods - 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.
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Default 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.


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [¬º-°]¬
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 03-30-2011, 10:48 AM

Quote:
Originally Posted by timsally View Post
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!


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
Reply With Quote
Old
kompsci
Guest
 
Status:
Posts: n/a
Default 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
   
Reply With Quote
Old
reuben2011
Senior Member
 
reuben2011's Avatar
 
Status: Offline
Posts: 489
Join Date: Sep 2009
Location: Hawaii
Default 04-15-2011, 05:50 PM

Quote:
Originally Posted by kompsci View Post
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.


Projects
-Escape the Kitchen
-That ninja animation
-Hill Collision

Upcoming Projects
-Some penguin adventure game?
   
Reply With Quote
Old
ebarrera
Junior Member
 
Status: Offline
Posts: 8
Join Date: Jun 2011
Location: Texas
Default 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.
   
Reply With Quote
Old
jaxadams
Junior Member
 
Status: Offline
Posts: 4
Join Date: Jun 2011
Location: Texas
Wink 07-07-2011, 04:24 PM

I agree either method would work well.
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.