Alice Community  

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

Reply
 
Thread Tools Display Modes
Key events
Old
jrrTolkien
Senior Member
 
jrrTolkien's Avatar
 
Status: Offline
Posts: 166
Join Date: Feb 2014
Location: Middle-Earth (Merrimack, NH)
Exclamation Key events - 05-24-2014, 06:58 PM

Okay, so I'm trying to make a racing game in Alice, but I have encountered an error in my programming. I have "while UP is pressed, do car.drive" I made it "realistically" accelerate (I think it's realistic, anyway.) Then, I have "after (the key is pressed), do car.stop." Then, it slows down. I attached my program so you can see how it works and everything. The problem I have is that when I let go of the button, it slows down until the mph hits 0. If I try to speed up again, it won't until mph reaches 0. Is there some way to speed up while keeping the acceleration and deceleration? If I'm not being clear, please say so.

-Jrr
Attached Files
File Type: a2w carTest.a2w (351.4 KB, 26 views)


Arwen: I would rather share one lifetime with you than face all the Ages of this world alone.

-April Signature
   
Reply With Quote
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 249
Join Date: Dec 2012
Location: Frosno, Ca
Default 05-25-2014, 09:03 AM

Quote:
Originally Posted by jrrTolkien View Post
Okay, so I'm trying to make a racing game in Alice, but I have encountered an error in my programming. I have "while UP is pressed, do car.drive" I made it "realistically" accelerate (I think it's realistic, anyway.) Then, I have "after (the key is pressed), do car.stop." Then, it slows down. I attached my program so you can see how it works and everything. The problem I have is that when I let go of the button, it slows down until the mph hits 0. If I try to speed up again, it won't until mph reaches 0. Is there some way to speed up while keeping the acceleration and deceleration? If I'm not being clear, please say so.

-Jrr
Go to the car.stop method and remove the enclosing while loop.
From your other code, I assume you understand how the events work but liking the sound of my own typing, I'll say the following:
As long as the event is active (the key is pressed, XXX is true ...) the event works like loop. Each time the triggered method ends Alice checks to see if the event is still active and if so calls the method again.
The difference between this and a method with an infinite loop, besides the fact that there is an event to test, is that Alice controls the scheduling. This means that other events and methods can happen "at the same time." A method with an infinite loop "blocks" keeping anything else from happening until it is done (which is never.)

Mark


Mark Henwood
mhenwood@ieee.org
   
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 ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.