Alice Community  

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

Reply
 
Thread Tools Display Modes
Help on sequence of triggered events?
Old
SCarroll
Junior Member
 
Status: Offline
Posts: 9
Join Date: Dec 2012
Question Help on sequence of triggered events? - 01-10-2013, 06:14 PM

I am working on the Save the Lunch Lady assignment (Chap 6 - Pg 210 in Learning to Program with Alice). I have it working up to when the 3rd tray should turn when I click on the Ninja. I have tried several combinations, but I can't figure out why I can't continue to turn the trays when a Ninja is clicked. Many of the combinations I tried ended up turning all the trays at once.

I am attaching what I have completed so far. Any direction is greatly appreciated. My assignment is due this weekend.
Also: Here is the actual assignment if you need any additional information -
Create a game where the goal is to save the Lunch Lady from the danger of an Evil
Ninja. A ninja will appear at random locations within the cafeteria, pause for 1 second,
and then disappear, only to reappear at another random location. The player’s task is to
click on the Ninja each time it appears in the world. Each time the player is successful
in clicking on the Ninja, a cafeteria tray will appear (upper left of the window). To win
the game, the Ninja has to be clicked five times (and five cafeteria trays be displayed) to
send the Ninja away forever.
Create a world and add the Cafeteria, the LunchLady, two CafeteriaTables, and
several CafeteriaChairs (all from High School). Add the EvilNinja (from People).
The first goal is to get the Ninja to move around to random locations within the cafeteria.
Create a method named moveAround for the EvilNinja. This method should
move the ninja a random distance from where it currently is, without moving off the
screen.
To check whether the player has successfully clicked on the Ninja, create a
method named checkIfNinja for the Ninja. The checkIfNinja method will need an
object parameter named who. Create an event When the mouse is clicked on anything,
and have it call the checkIfNinja method, sending the object clicked to the who
parameter
Attached Files
File Type: a2w SavetheLunchLady2.a2w (2.87 MB, 17 views)
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 01-11-2013, 09:34 PM

Some times it is good to outline what you want to do and then make the code follow your outline.
In the present case you initially start with all the trays opacity set to 0.2, for all practical purposes invisible. Each time the ninja is clicked on the opacity of the next tray should be changed to 1.0. So, for any particular click only one tray should change its opacity. This calls for a series of nested if statements. Each if clause will test one tray's opacity if it is 0.2 then change it to 1.0 and exit the method. If the tray's opacity is at 1.0 then we have already made that tray visible so check the next tray. If you have checked each tray and they are all visible (opacity == 1.0) then the user wins.
if tray1.opacity==0.2
tray1 set opacity to 1.0
else
if tray2.opacity==0.2
tray2 set opacity to 1.0
else
if tray3.opacity==0.2 ....

Hope this helps
Mark
   
Reply With Quote
Still an issue
Old
SCarroll
Junior Member
 
Status: Offline
Posts: 9
Join Date: Dec 2012
Unhappy Still an issue - 01-11-2013, 09:44 PM

On my checkIfNinja method, that is what I have unless I totally misunderstood what you are explaining. I still get 2 trays to turn when I click the ninja the first time.


Were you able to view my attached World?

Last edited by SCarroll; 01-11-2013 at 09:51 PM. Reason: Update
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 01-12-2013, 10:17 AM

What you sent me:

Code:
evilNinja.checkIfNinja (obj Who)
  If Who == evilNinja
    If 1point.opacity == 0.2 
      1point set opacity to 1
      Do in order
        3point set opacity to 1
        4point set opacity to 1
        5point set opacity to 1
    Else
        2point set opacity to 1
  Else
    Do Nothing
-- STOP HERE Look at the above, what does it do? --

Translation:
If the user clicked on the EvilNinja then, if the first tray is not visible make it visible and make trays 3, 4 and 5 visible. Else (the first tray is visible) make tray 2 visible.
   
Reply With Quote
Still not working
Old
SCarroll
Junior Member
 
Status: Offline
Posts: 9
Join Date: Dec 2012
Unhappy Still not working - 01-12-2013, 10:40 AM

This makes 1, 3, 4, and 5 trays show when I click on the evilNinja the first time.

I need each try to turn in sequence each time the ninja is clicked.

THANKS SO MUCH FOR TRYING TO HELP ME !!!!
   
Reply With Quote
Thanks............I got it working!
Old
SCarroll
Junior Member
 
Status: Offline
Posts: 9
Join Date: Dec 2012
Default Thanks............I got it working! - 01-12-2013, 03:41 PM

Appreciate your input!
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 01-12-2013, 06:55 PM

Great
   
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.