Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
variable named... tile
Old
squirmonkey
Guest
 
Status:
Posts: n/a
Default variable named... tile - 10-14-2007, 12:58 PM

I have several instances of type kidRobot in my world.

I am trying to write a world method that takes a parameter which will be a kidRobot, and do something in that method based on a variable that I created and added to kidRobot.

My parameter is named who and is of type Object.

I am trying to use the ____'s variable name ____ of type _____ tile in an if/else but it won't let me drag that tile there. (I want "who" to be in the first blank) How can I evaluate and make use of the value of who.health (health is my variable that I created)

Thanks!
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 10-14-2007, 02:06 PM

Quote:
Originally Posted by squirmonkey View Post
I have several instances of type kidRobot in my world.

I am trying to write a world method that takes a parameter which will be a kidRobot, and do something in that method based on a variable that I created and added to kidRobot.

My parameter is named who and is of type Object.

I am trying to use the ____'s variable name ____ of type _____ tile in an if/else but it won't let me drag that tile there. (I want "who" to be in the first blank) How can I evaluate and make use of the value of who.health (health is my variable that I created)

Thanks!
I have never tried to do exactly what you describe, but I strongly suspect that the restriction that I explain in the following references is causing your problem. When you pass an object to a method as type Object, the code in the receiving method doesn't have access to custom methods belonging to that object, and I would guess also doesn't have access to custom properties or variables belonging to the object either. This is because Alice doesn't support polymorphism or casting.

Take a look at the following references to see if they contain the answer to your question.


See http://www.dickbaldwin.com/alice/Ali..._cast_operator

Also see "A serious restriction" at http://www.dickbaldwin.com/alice/Alice0145.htm

Dick Baldwin
http://www.dickbaldwin.com/toc.htm
http://www.dickbaldwin.com/tocalice.htm
   
Reply With Quote
Old
squirmonkey
Guest
 
Status:
Posts: n/a
Default 10-14-2007, 02:16 PM

If I know that the "who" parameter is always going to be of type kidRobot, is there some way to create it as a parameter of type kidRobot rather than of type Object? Then I wouldn't have to cast it.

What is the point or use of the ____'s variable named ______ of type ______ if you can't use it in a context like this? I couldn't find any place I could drag it except into a print statement.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 10-14-2007, 02:33 PM

Quote:
Originally Posted by squirmonkey View Post
If I know that the "who" parameter is always going to be of type kidRobot, is there some way to create it as a parameter of type kidRobot rather than of type Object? Then I wouldn't have to cast it.
If there is a way to pass an object to a method as any type other than Object, I don't know what it is. Also, if there is a way in Alice 2.0 to gain access to anything other than the primitive methods and properties of an object passed as a parameter to a method, I haven't figured out what it is either.

However, there is something named "part named" that some people mention as a possible workaround for this issue that you may want to look into. I looked into it when I first became involved with Alice and concluded that it is so foreign to my concept of OOP that I won't even mention it to my students. However, since you are not one of my students I will mention it to you.

I am really anxious for the release of V3.0, which supposedly will be fully object oriented and will eliminate many of the current problems with Alice 2.0.

Quote:
Originally Posted by squirmonkey View Post
What is the point or use of the ____'s variable named ______ of type ______ if you can't use it in a context like this? I couldn't find any place I could drag it except into a print statement.
I will pass on this question and let someone else provide a response.

Dick Baldwin
http://www.dickbaldwin.com/tocalice.htm
http://www.dickbaldwin.com/toc.htm
   
Reply With Quote
Using "part named"
Old
DrJim
Guest
 
Status:
Posts: n/a
Default Using "part named" - 10-15-2007, 10:12 AM

The following is from memory since the archives for the forum seem to have disappeared and I didn't keep copies of the programs I wrote. But basically the "part named ---" can be used to pass a specific objects part when calling a method. Lots of funny restrictions - don't think you can actually drag and drop this unless you've already put a valid variable in the call, for example (something not uncommon in Alice). Also a couple of very reasonable requirements. For example, the object has to have a "part named" and the entire naming hierarchies, except for the top level object name, have to be identical, for example.

There is an example in the Dunn text (which I also don't have right now) somewhere around the middle of the book. It may be the Zeus example - if not, it's in that general area of the book. Maybe someone can be more exact.

I also did do a couple of example worlds a year or so ago, so if the archives come back, they may be of help. But overall, I tend to agree with Dick - the function is of limited utility and very foreign to any OOP teaching objective that I can think of.
   
Reply With Quote
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default 10-27-2007, 10:31 AM

Quote:
Originally Posted by squirmonkey View Post
If I know that the "who" parameter is always going to be of type kidRobot, is there some way to create it as a parameter of type kidRobot rather than of type Object? Then I wouldn't have to cast it.

What is the point or use of the ____'s variable named ______ of type ______ if you can't use it in a context like this? I couldn't find any place I could drag it except into a print statement.
See new information at http://www.dickbaldwin.com/alice/Ali...of_type_Object

Maybe that will help.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm
   
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 ©2022, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.