Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Variables (http://www.alice.org/community/showthread.php?t=1745)

Scott 09-25-2008 07:07 PM

Variables
 
1 Attachment(s)
Hey,

I am taking Computer Science at school and we are using Alice. Recently I have been working ahead and know a bit more stuff than we have learned. Yet the one thing I do not understand is variables. I read over and over the part where you learn it in the book in the classroom and tried it but couldn't get it to do what I wanted.

Let me say that I am making a game. You are a guy in a Beach Chair and you go around and hit chickens and get 100 points. I have the chair as the guys vehicle and the chair the camera's vehicle so they are all synced. I have 3 chickens in the level so far that go in circles. And as of now The guy goes right through the chickens.

First question I have is how do I make it as when the Chair hits a chicken, the chicken falls and gives you 100 points. I tried for a half hour but couldn't get it to work. I know I need to use the IF thing, and I know what to do, just don't know how to put it down. I want it to be like "If Beach Chair hits chicken, make Chicken Fall". Next part of this question is how do I get this to work when there are more than 1 chicken. There will many many many chickens, like maybe up to 30 or 40. How do I set it to get to hit any chicken for this IF statement to work. Because it lists the chickens as Chicken 1, Chicken 2, and so on. And I don't think making 40 IF statements is necessary.

Next question is how do I get a score system. I know how to get text and position it in the left corner of the screen, but how do I get the score to change up 100 points when you hit a chicken.

I have the file attached and would like to hear back from someone on how to do this. I have only been in this class for 4 weeks. And I do not mind anyone to do what I need to my file and re attach it. I would really really appreciate it if you did because I can learn best seeing it like that.

Chris101b 09-26-2008 12:18 AM

1 Attachment(s)
Well, since no one else has said anything, ill try to help in the best way I can. I know how to make the chickens move down when the chair runs them over but am unsure of how to do scores. And unfortunately, my way of doing it involves making a function for every chicken in your world. Attached is the modified version I did. To do this, click on the button on the main screen at the top that says "Create New Event". Now click on "While Something is True". Now click on the chair and then go to the functions bar on the left and drag the "chair is within threshold" box up into the "While" Section of the event you just made. Now set it to 1 meter and then set it to chicken 1. Now notice how right below that it says:

Begin:
During:
End:

Well, click on chicken 1 and drag a thing that says "chicken move down 5 meters" into the begin box. Now what this says is that when the EXACT MIDDLE of the chair is 1 meter from the EXACT MIDDLE of the chicken, the chicken will move down 5 meters. Now the reason I specify the whole EXACT MIDDLE thing is because when you say within 1 meter, it is talking about the middle of the object. If you put it on 0, and the leg of the chair touches the tail of the chicken, it wont do anything. So setting it to around 1 meter does good. Ill attach the file below. Hope this helps even a little bit.

Scott 09-26-2008 08:01 PM

Thanks
 
Thanks :)

Now I just need someone to help with scoring.

Scott 09-26-2008 08:41 PM

Cool.
 
I just tried it. Love the way you did it. I didn't think of getting it to do that in the top part. Now I have a template to get the rest of the chickens done :) Thanks.

Chris101b 09-27-2008 07:40 PM

Glad I could help. I have the same problem as you do. I don't understand how to make variables either even thought I read over the tutorials over and over, so I am the type of person that tries to find the easiest alternative, and this way works the best. But the only thing is that you have to do it for every chicken. You can probably find some other tutorial on how to do that somewhere in this forums.

Scott 09-27-2008 10:30 PM

Yeah. This was seems to work fine enough. lol

I finished doing that for about 6 more chickens. so now i have some progress. :)

The book is confusing. I see a green background and so it is in the function or whatever tab but then the next part in the book is in the regular default World.MyFirstMethod.

But I don't intend to dwell on Alice stuff THAT much since this class is about Java and we are using Alice to start. But it all will help though later on I guess.


All times are GMT -5. The time now is 07:27 PM.

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