How do I have Selective Constant Sound?

Hello! I’m almost done with my first GDevelop game (yayyy!) but I’m stuck on ONE sound effect not working for me to say the gameplay part of the game is done.

Here is what I’m going for: Its a game where you put toppings on a pizza kinda like the old dress-up games. I have shakers for parmesan cheese, pepper flakes, and Italian seasoning. I want it to play a sound when it interacts with the pizza crust but ONLY then. But I also want it continuous when it plays. Since if you use a shaker it makes sounds until you put it down.

I’ve tried trigger once, I’ve tried without it. Loop on, loop off. A combo of all those. I even told it to turn off the sound if I’m not interacting with the crust. Nothing wants to work. I’m obviously doing it wrong :expressionless:

Here’s a video since I suck at explaining things.

I read the sound documentation I found on google, I read some other threads none of it helped that I found. :frowning:

If anyone can help that would be great! Thank you :3

There’s something not right there. That “trigger once” is actually “trigger once while true”, and on the collision it will work every time the collision condition changes from false to true. The first time the collision happens it triggers the event, and when the spice_bottles is removed it should reset that condition, so that it is triggered again the next time a spice_bottles object is dragged over a crusts object.

Because it only seems to work once points to there being an ongoing collision between spice_bottles and crusts, preventing it from repeatedly being triggered when a spice_bottles object is dragged over the pizza.

What are you doing with the spice_bottles object when the mouse is released and it’s no longer being dragged?

1 Like

When the spice bottle interacts with the crust it spawns the seasonings as small objects and stops when I stop holding it.

Yes, I understand that part. What I don’t know is what happens to the spice bottle object when you stop dragging it. Is it moved somewhere, deleted, hidden?

1 Like

Turn off loop
And not play sound on channel (that you pick for music)

But just Play Sound

1 Like

Ohhhh. I made it snap back to it’s original position when it isn’t being dragged.

I did that too and it didn’t work…unless I keep selecting the wrong one? It’s not play music it’s play sound I’m using. I also tried with loop off it didn’t do what I want. Or do you mean make the channel 0?


1 - you use to play any sound
2 - you use to play music

NEVER use play music action

1 Like

IDK proper words in english so try to understand what i mean
You want to play sound when you for example have salt container held by you with LMB but only when you are shaking over pizza?
Like each time you shake you want to play sound
Is that what you are going for?
If so then you have 2 options
(just side note my post above is still accurate)

Option 1
While object you hold check collision of that object with pizza
BUT also you need to check if mouse position changed
And since you have object attached to it atm it will be easier
Here i am doing it for selector
You do it for object you are holding for example salt container

Order of events is important you can’t have top the one from the bottom where i change variables with no conditions on top or it will not work
It needs to be on bottom

And in my case each time selector changes position it plays sound

I guess in your case you will spam it if that will be the case we will figure something else

Option 2

Since you use 1 item to spam something over other item (literally as you would shoot a bullet or arrow)
Why not use that event to play sound?
For example you create salt grains on pizza when you shake salt container
SOOO why not when creating salt grains play sound?

That would and i do mean sound of salt container shaking which would still make sense and sound natural

Also .aac files are supported by more devices than .wav files
Use this to convert them

1 - select your encoder
2 - drop your audio files here
3 - hit this button to start converting

Anyway i bet both of my methods won’t be perfect and will need tweaking but they are good start

So after you got it working come back here and we gonna adjust whatever will be wrong

1 Like

I use .ogg, but its good to know! Thanks! :smiley:
I don’t use the music conditions is it sound.

I don’t know how to do variables, I watched the official videos multiple times I don’t understand them.
So I can’t do your first option right now, I have to understand better. - I tried the second option, it technically works but the sound keeps making new instances if playing so it just sounds like a swarm of the same sound instead of the one sound playing.

I feel like your variable idea would probably work better, but I don’t know how to do what you showed. I don’t even know how to copy it. I did try and I couldn’t even find “If one of these conditions is true” to even start. :frowning:

I was camping 3 months before i decided to get into variables
Because i was sure it some high level technical stuff
Never in my life i was so wrong
Imagine variables as indicators of something
Which you can turn to something or check if they are something

Most simple example
There are boolean variables
As cryptic as that sounds they have only 2 states False (set by default so if you create boolean variable it default state will be False) and True
So in other words you can say they are either 0 or 1
OR turned OFF or turned ON
So most basic example we have light bulb
Now imagine you place that bulb in your game and by default it is in False state (off)

Now you have ability to

  • check state of that variable (is it true or is it false)
  • toggle its state (if it is in true state this action will toggle it to false state and if it is in false state this action will toggle it to true state)
  • set it state to false or true (no matter at what state it is you can set it to one of these 2 states at will)

Now imagine it as that bulb
You check if it is turned ON or turned OFF
You can with one button always turn it OFF or with another button turn it ON
You can toggle it state so if it is turned ON it will turn it OFF and vice-versa

Imagine you have condition cursor is on start button
And you make action for that condition to set boolean variable named LightBulbState to True
And another event
Where in condition you have that if mouse cursor is NOT on start button
Set Light BulbState to False

Now you can check at any point in your game with any event
In condition
If LightBulbState = Trune (bulb is turned ON or as you wish cursor is on start button)

And it is as simple as that

Now there are number variables that works more or less the same
But instead of True and False state they have well numbers
So you can do a counter
For each pepperoni you add to your pizza you change Ingredients number variable Add +1
And so number of that variable went from 0 to 1
You added another one and now variable from 1 to 2

Maybe you wanna do something different?
Like HP of your player
You make event
Condition
At beginning of the scene
Action
Change object number variable Player.Variable(HP) set to 100
This instead of adding a number will simply change this variable number to 100

Now you can do event like
Condition
Plyer is in collision with bullet
Action
Change object number variable Player.Variable(HP) subtract 5

So each time player is in collision with bullet this event will subtract 5 from Player HP variable 5

Now you can use text object to display this HP variable as text
For example you create text object place it on your scene and in event
Condition
NONE

Action
Modify text of NewText (<- this will be name of new text object) set to
ToString(Player.Variable(HP))
And now it will display player current HP

As for if one of these conditions is true
There are few of these types of conditions
Click add condition
And in search bar type

  • and
  • or
  • not

I think there are few more but i never used them and these are the ones you will actually use

If you need/want to learn more about variables i can explain more give more examples and teach you

BUT trust me you are just like me believing they are more complicated and cryptic than they actually are

For another example
In this order from top to bottom
Global
Scene
Object
variables are called in events with

  • GlobalVariable(VARAIBLENAME)
  • Variable(VARIABLENAME)
  • OBJECTNAME.Variable(VARIABLENAME)

For example you do not want to go with object variable for player
But global variable
Then instead of Player.Variable(HP)
You would go with GlobalVariable(PlayerHP)
I changed name from HP to PlayerHP
Because if you for example have boss you can’t have 2 global variables with same name which would be HP
So instead you would go with
GlobalVariable(PlayerHP)
GlobalVariable(BossHP)

And you can set them to whatever you want and change them when each object is in collision with something or at some position

1 Like

Forgot to address sound issue
If my 2nd method kinda works as you describe it

Solution could be

You have there condition for (i forgot names and am too lazy to check so) Salt container is in collision with pizza
Add to it condition
Salt container current frame is 1 (which is actually 2nd frame since 1st is 0)

And add trigger once to it
NOW sound will play only when 2nd frame of animation is played
Or IF sound is too frequent
Option A
Increase time of animation
Go into your salt container object (double click it) and simply change time to some higher value

OptionB
Again double click your salt container object and right click on frames and choose duplicate frame
Duplicate each of them and place them in correct order
Now instead of it going from frame 0 to frame 1 and back to 0
it will go from frame 0 to 1 to 2 to 3 and then back to 0
This way sound will play only at frame 1

You are not duplicating images you are just saying your game to show/play some image again
So do not worry you are not duplicating files here

Be sure to add that trigger once
BUT if for some reason it won’t properly work with trigger once for sure it will without it
But i think you need trigger once there

1 Like

Thank you for explaining it to me!
My brain needs time to process it but I think I’ll get it. I’m probably over thinking I do that a lot! XD
I appreciate all your help :smiley:

1 Like

I tried option A making the animation frame one an if statement so like… If the animation frame =1 trigger once, and play the sound no loop. It seems to work so I’m hype! Thank you so much!! :smiley:

1 Like

Do not use OR statement for one condition
Do not use AND statement for conditions if it is not inside OR statement

For sound playing for salt container this should be enough

About OR and AND statement

This makes no sense


Since you have only ONE condition there

But if you would have multiple like


This would make sense
Because instead of making two separate events for checking frames you check them in one
So if one of these conditions is true it will play sound

As for AND
Both these events make no sense



Because by default event is checking if all conditions are true
And using AND statement in condition like i made above can literally freeze your game
If i remove AND and just leave 1 or these 2 conditions there it would work perfectly fine

Proper way to use AND is

We are checking here if animation is either 0 or 1
Imagine animation 0 is standing
While animation 1 is running
But i wanna play sound on frame 2 of each animation

So my soldier is firing at frame 2 of it’s idle or running animation
Then i play sound
Instead of making 2 separate events
I check if
Animation is 0
And frame of that animation is 2

OR

If animation is 1
And frame of that animation is 2

This is only correct way to use AND when it is inside OR
Again
OR = if one of these is true
AND = if all of these are true

Have fun

1 Like

Have you tried “play a sound” instead of “play a sound on a channel” ?
Or maybe you can try this:

1 Like