play a sound every time hit a tile.

jcdsr

  • Posts: 10
I'm doing the tutorials on "learning with stencyl book 3.x" however the editor miss how to add the sound when the "statue actor" hit a tile. On this tutorial, the "statue actor" move from top to bottom, but when the actor hit those tiles I a get too many hits, obviously when a add a sound to the game just crash, because it detect too many hit at once.

I test two codes, however the boolean one just play the event only the first time, but the "stone actor" doesn't hit just one, hit like 3 to 4 times or more as end user.

I would like to the detected this instead the simple code I use which show me like 200 time the same print on log viewer.

Please find attached some screen shoots, 
Note the red point are a representation when the "stone actor hit"

Hope make sense!

Rares

  • Posts: 216
The boolean one, it will only play once because once you've hit a tile, it sets statute hit to true, you need to set it somewhere to False again.
Last version (0.1.5) of my now cancelled game:
http://www.stencyl.com/game/play/27241

jcdsr

  • Posts: 10
didn't work, still printing too many.

Rares

  • Posts: 216
when self hits something
set  statute hit to true

when updating
.
if statute hit is true
play sound
*end of if statement*
set statute hit to false
.

In that order, because when it's not hitting it it will be set to false, while it is hitting it, the variable will remain to true while the actor is still on it, thus playing the sound only once (or so in my mind). Once it gets off it, it will be set to false, therefore next time something collides with it again, it will play the sound.

Last version (0.1.5) of my now cancelled game:
http://www.stencyl.com/game/play/27241

jcdsr

  • Posts: 10
Nop, still printing too many. I create a game test.

I didn't add any sound. watch the log viewer. (word hit)

File attached.

gamegirlxl

  • Posts: 716
I think that creating a Boolean that becomes false when the collision happens, then x seconds later it should become true again, where x is the length of the sound.  If you put the play sound and set Boolean inside an "if <Boolean>" wrapper, it shouldn't happen excessively.

jcdsr

  • Posts: 10
I try that and didn't work because some times the actor hit the tile before the time is finish

gamegirlxl

  • Posts: 716
Maybe you should extend the delay timer.  It should work if it's done properly...

jcdsr

  • Posts: 10
That doesn't work for me

gamegirlxl

  • Posts: 716
That doesn't work for me

What does it do (for you)?  I suspect that you might be doing something wrong.  Are you putting both the timer AND the setter within the IF statement?

Although I haven't actually tested this code, I'm usually able to write working code without testing it.  Also, without seeing your project, I'm pretty certain that you don't realize that things collide once per frame, 60 frames per second.

Sunrisekingdom

  • *
  • Posts: 75
I want to let everyone know, I will be taking requests for tutorials, so if you would like to see a specific tutorial made, comment here
http://community.stencyl.com/index.php/topic,1233
or email at Sunrisekingdomtutorial@gmail.com
Stencylworks video tutorial http://www.youtube.com/watch?v=KDfRfjzr9j4&
My Site http://sunrisekingdomarcade.weebly.com

Extintor

  • Posts: 5
Ok, i saw that this coment is from 2014 but... i have the same doubt and the "videosolution" is removed.... Can anyone help me, please? Thank you.

NickamonPoppytail

  • *
  • Posts: 825
Ok, i saw that this coment is from 2014 but... i have the same doubt and the "videosolution" is removed.... Can anyone help me, please? Thank you.

Try this:

When <Actor> hits something
Set <Boolean Attribute 1> to true

When Updating
If <Boolean Attribute 1> = true and <Boolean Attribute 2> = true
Set <Boolean Attribute 1> to false
Play <Sound>
If <Boolean Attribute 2> = false
Do after get length for <Sound> seconds
Set <Boolean Attribute 2>

The first Boolean Attribute checks if the actor hit a tile and the second detects whether the sound is already playing. I haven’t tested this, but that should work.
I’m the guy who made the Poppytail series, The World of Elecreatures, Century Game and Easter Fun.

Email: nick.rosemarygames.poppytail@gmail.com

;)