Alice Community  

Go Back   Alice Community > Alice 3 > How Do I?

Reply
 
Thread Tools Display Modes
Alice3-collision event + variables
Old
coynerm
Junior Member
 
Status: Offline
Posts: 5
Join Date: Sep 2013
Default Alice3-collision event + variables - 12-14-2015, 01:10 PM

Trying to create a global counter variable to keep track of collision events ie each time an object collides then increment counter but...can only create local variable for each collision event. Is there a way to create a global variable in the initializeEventListeners?

Also, why doesnt the 'object.isCollidingWith.otherObject' function work? I tried using this but it didnt detect the collision so I went w/ the eventListener for collision detection. If I can get this function working then I can create a global variable....thx.

Mike
   
Reply With Quote
Old
chicky371
Junior Member
 
Status: Offline
Posts: 3
Join Date: Apr 2018
Location: I live in Ho Chi Minh city, Vietnam
Default 04-30-2018, 07:52 AM

Quote:
Originally Posted by coynerm View Post
Trying to create a global counter variable to keep track of collision events ie each time an object collides then increment counter but...can only create local variable for each collision event. Is there a way to create a global variable in the initializeEventListeners?

Also, why doesnt the 'object.isCollidingWith.otherObject' function work? I tried using this but it didnt detect the collision so I went w/ the eventListener for collision detection. If I can get this function working then I can create a global variable....thx.

Mike
In 'isCollidingWith' function, if you want it to work while the program is running, you should put it into 'while' statement because it is a condition, if you set up it once, the program just compares one, and then passes it, so i think while statement will help you repeat until the condition is true.
   
Reply With Quote
Collision Count
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Collision Count - 04-30-2018, 12:29 PM

Quote:
Originally Posted by coynerm View Post
Trying to create a global counter variable to keep track of collision events ie each time an object collides then increment counter but...can only create local variable for each collision event. Is there a way to create a global variable in the initializeEventListeners?

Also, why doesnt the 'object.isCollidingWith.otherObject' function work? I tried using this but it didnt detect the collision so I went w/ the eventListener for collision detection. If I can get this function working then I can create a global variable....thx.

Mike
Select the scene and add a "scene property" this will act as a global value you can update with each collision.
Although my example works, real programs should not use a "while true" loop for several reasons. These reasons include performance and interaction with other methods/functions.

Mark
Attached Files
File Type: a3p Collision.a3p (35.0 KB, 27 views)


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 ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.