Alice Community  

Go Back   Alice Community > Educators > Teaching with Alice

Reply
 
Thread Tools Display Modes
help with 4.1.1 of "Learning to program with Alice"
Old
itrickski
Guest
 
Status:
Posts: n/a
Unhappy help with 4.1.1 of "Learning to program with Alice" - 11-04-2006, 12:03 PM

I am teaching Alice from the text "Learning to program with Alice" In chapter 4, we have covered methods, and I'm working question 4.1.1, where snowman tips his hat to snowwoman, then snowwoman tips her hat back.

I thought the idea of this problem was to create a method called "fliphat", which could be called for either the snowman, or snowwoman. however, when i create an object parameter for the method, i cannot substitute the parameter in the correct place

snowman.leftarm roll becomes
objectparam roll

creating 2 fliphat methods (one for snowman and one for snowwoman) seems to defeat the purpose of a method. what am i missing? any help is greatly appreciated!!
   
Reply With Quote
Don't get mad, get glad...
Old
Shadow Sovereign
Guest
 
Status:
Posts: n/a
Smile Don't get mad, get glad... - 11-04-2006, 01:42 PM

Don't worry, I had a load of trouble trying to get this one to work. When I did it, I found that it was easy to get them to tip the hat off of their head, but my problem was getting it back to its original place...

What I did was basically trial and error. The trick is trying a Do Together with both Roll and Movement commands to get the hat back on the head.

I hope I helped!
   
Reply With Quote
Problem is making method generic
Old
itrickski
Guest
 
Status:
Posts: n/a
Default Problem is making method generic - 11-04-2006, 04:12 PM

thanks for the input. i have the code working to get snowman to "tip the hat". the problem is that i cannot use that same method for snowwoman. it seems that i should be able to create 1 method called Tiphat and call it for the snowman, and the snowwoman, like

tiphat(snowman)
tiphat(snowwoman)

however, because the method uses the snowman's arm, i cannot do that

snowman.leftarm DoSomeMethod becomes
objectpassed DoSomeMethod instead of
objectpassed.leftarm DoSomeMethod

is there a way to make the method "generic" instead of having to create 2 methods?
snowmantiphat() and
snowwomantiphat()
   
Reply With Quote
An example for you...
Old
Shadow Sovereign
Guest
 
Status:
Posts: n/a
Default An example for you... - 11-04-2006, 05:50 PM

Here's something to help explain this. It's quite simple, actually...

All you do is when you have two similar methods for two different objects and you want to change the subject for the method you want to change, all you do is you go into the target object and change it to the EXACT object you want affected.
Here's a 1 second world to demonstrate my point. In the first picture, notice that I have the dragon and the robot moving up. Now notice the code in the second pic, I changed the 'dragon' target to 'robot, so now the robot will move up twice. It works similarly with full methods...

Lemme know how it works for you.
Attached Images
File Type: jpg ss1.JPG (46.2 KB, 332 views)
File Type: jpg ss2.JPG (46.7 KB, 354 views)
   
Reply With Quote
Generic method call - one (the only?) way.
Old
DrJim
Guest
 
Status:
Posts: n/a
Question Generic method call - one (the only?) way. - 11-04-2006, 06:01 PM

I'm assuming what you want is to make a generic call - not edit the program for each object. I'm also not including lists, which would make the program read easier but just packs the basic problem in a more compact form.

To make the method generic, you have to define a parameter for every object involved in the animation - and then pass values for all of the parameters if you don't want to use the defaults - see attached. (Note that snowman_whitehat.head is not the same as snowman_readhat.head and also that you can't use snowman.head as a parameter - you get an error (name turns red) when you try.)

The same problem arises when you save the snowman object with the new method as a "new class". You get another copy of the parameterized method, with a different name, every time you import or instantiate the new "class." (I'd like to be wrong on this, it really isn't a positive thing. If I am, somebody please show me my error and how to correct it.)
Attached Files
File Type: a2w snowHat.a2w (188.1 KB, 597 views)
   
Reply With Quote
Old
Shadow Sovereign
Guest
 
Status:
Posts: n/a
Wink 11-04-2006, 06:06 PM

[QUOTE=DrJim;1558I'd like to be wrong on this, it really isn't a positive thing. If I am, somebody please show me my error and how to correct it.[/QUOTE]

I highly doubt that you're wrong at any given time.

I would try his way first.... DrJim is a very experienced Alice-user. More than I am, anyway...

Edit: The quotey-boxey-thingy didn't work right, but he did say that. Pleez don't sue me for plagiarism! (Just kidding)

Last edited by Shadow Sovereign; 11-04-2006 at 06:08 PM. Reason: Quotey thing didn't work right...
   
Reply With Quote
The question I intended.
Old
DrJim
Guest
 
Status:
Posts: n/a
Exclamation The question I intended. - 11-06-2006, 06:31 PM

Quote:
Originally Posted by Shadow Sovereign View Post
I highly doubt that you're wrong at any given time.
If that's referring to me, you give me far too much credit - but if you do think that, did I mention I could get you a naming deal on a resturant?

Suspect what you did with the "quote thingy" was delete one or more of the control characters surrounding the quote - that can really do funny things. I haven't found any guides for those - when I goof up (obvious if you preview a message), I generally just start over.

What I was really asking in the initial post is whether there is a way in the "drag-and-drop" environment to preserve a "parent.child1.child2." type naming convention. It seems to be available when you enable scripting (I haven't tried it very much) but I can't find any way to make something similar work in the basic Alice environment
   
Reply With Quote
In any case....
Old
Shadow Sovereign
Guest
 
Status:
Posts: n/a
Lightbulb In any case.... - 11-07-2006, 03:16 PM

Well, I dunno about a naming job with a restauraunt (unless if it's that 'Pickles' thing again ), but I would still try DrJim's way first.

However, in the event that it doesn't work (like getting a blue screen of death or something ), don't panic........... ok, I was just kidding about the blue screen of death thing. Seriously, my way is that since I'm not too hot on the parameter thing, is to make effective use of the clipboard in your upper right corner. Just make one method, put in the correct code, and if it works for one object, make the other method, and copy the first code to the second method and change the target object like I have displayed several posts up. /\ /\
|| ||

Hi.
   
Reply With Quote
Jedi master Dr. Jim
Old
itrickski
Guest
 
Status:
Posts: n/a
Default Jedi master Dr. Jim - 11-09-2006, 04:48 PM

Thanks for the sample Dr. Jim...I think I see what's going on. Will study this a little more and see what I can figure out.

- all the best -
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.