View Full Version : help with 4.1.1 of "Learning to program with Alice"

11-04-2006, 01: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!!

Shadow Sovereign
11-04-2006, 02: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! :)

11-04-2006, 05: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


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

Shadow Sovereign
11-04-2006, 06: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. ;)

11-04-2006, 07: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.)

Shadow Sovereign
11-04-2006, 07: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... :D

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

11-06-2006, 07:31 PM
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? :D

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. :confused: 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

Shadow Sovereign
11-07-2006, 04:16 PM
Well, I dunno about a naming job with a restauraunt (unless if it's that 'Pickles' thing again :rolleyes: ), 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 :eek: ), 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. /\ /\
|| ||

:D Hi. :D

11-09-2006, 05: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 -