Sound callback (text and sound sync) (SOLVED)

While it doesn’t directly say it, the last code example does show it as its own game object. I’m doing it that way in my game and it works.

@jweaver911

The article on gating does imply that you should make a new game object and send messages to it to play sounds. You would need to be familiar with message passing to understand that.

Re: beginner users. I started with defold two or three months ago and I think the documentation is pretty good (and the help that has been provided by this forum has been exceptional)… however, the fact is that making even simple games is a complicated undertaking. Many game engines (via marketing or simply via your own imagination and naivety) make you think that in no-time-at-all you will have made your first game. But the people who can make games very quickly have a large amount of experience behind them. I believe that whatever engine you use, you need to gain an understanding of a number of concepts that are generally logically consistent, but often unintuitive.

It’s also true that many people do not realise how long it can take before these concepts become obvious. The same thing happens with language learning, or learning to drive a car: once you have learned, it becomes bewildering to see other people struggle to change gear or steer while reversing.

3 Likes

@88.josh I agree… All that is true. And while I don’t find message passing to be that obtuse, I do find the path and url structure to be more elusive at times. That part is the confusing part for me. Editor 2.0 will help this as it displays the object urls in a readable and obvious nature.

@codecloak So the object just sits out in the level somewhere. Where do you have your sounds then? Do you recommend placing them In the game objects they’re playing for? Or would it be better to store them all somewhere else?

If I’m gating a sound, I put them on the sound gate object otherwise I put them where I need to play them.

1 Like

Interesting. Ok. :thumbsup:

@jweaver911 yes, I use print(msg.url()) all the time which prints an object’s URL to the console. Otherwise I can never figure it out.

I use a collection (which is always loaded) called “loader” to deal with all the loading and unloading of the levels (there are many in my game) and that is where I’d put the sound game object.

1 Like

Yeah… I’ve used msg.url() before but it doesn’t always seem to work. Like right now I have it in my init callback of my player and it’s outputting nothing.

EDIT: Ahh… Turns out my atom editor changes were not being updated in the game. Not sure how that happened.

@jweaver911 yeah, i’m always doing stuff like that (writing and rewriting a script only to discover that it was perfect the first time but I had failed to attach it to an object, etc). I’m curious to see how your game is looking!

@88.josh :slight_smile: Yeah, I’m not really sure what I’m doing with it yet. I intended to use this prototype as a tool for learning Defold. I wanted to make 2 players that can run around and chuck rocks at each other. Like a primitive Towerfall game :wink: Most of it’s all “thrown together” art.
I’m just about at the point where I can add second controller support for testing.

I have some other questions about how to do just that but they would be off-topic in this thread… as I’ve probably diverged enough already.

2 Likes

local two player is the best!!! I’ve always thought about making a compilation of two-games that could be done on mobile/tablets, because I think there aren’t many of those. Good luck!

Hey there.

Is there any solution to find out if a sound / music is finished???

nope, only make the table with timing of sounds and use the timer to catch complete event.

:frowning: crap

Is there a way to handle the volume/gain?

Yeah use openal extention for sync text and sound.

This my code:

in on_message receieve message from text source and start sound:

                        local res = resource.load("/Voices/"..self.currentSoundId..".wav")			
			self.soundSource = openal.new_source(res)
			if self.soundSource then
				self.soundSource.x, self.soundSource.y = 0, 0
				self.soundSource.is_looping = false
				self.soundSource:play()
    		end

in on_update wait sound stop state. If sound stop - send callback message to text source.

if self.soundSource then			
			local soundState = self.soundSource.state
			if soundState == "stopped" then
					self.soundSource:stop()			
					msg.post("#","SoundStopPlay",{soundId = self.currentSoundId})											
			end	
		end
1 Like

I make it on start, but now we hve openal extenstion and absent problem.

yep, openal is great! But there is one another problem - build size. If .wav files used instead .ogg for music for example.

For music you can use standart sound object and ogg.

of course, but if you want sequence of music (long level. etc,) you need to known when music file is done :slight_smile:

Solved in 1.2.162

2 Likes