Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / [SOLVED] Could not add sound file - No Free ID Found

Author
Message
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 17th Nov 2018 15:10
Hi all
I'm getting the above error in my shoot 'em up type project that I've been working on for a few day, and it's driving me to distraction.

I have a #constant, lasersnd, set up loaded with a wav file "laser.wav" from one of the example projects.



This is passed to a "create bullet" function, when the fire button is pressed and a 'bullet' fired. Works great until somewhere around 220 - 260 bullets have been fired, then the game crashes with the error in the title.





The help states that the sound instance is deleted when the sound has finished playing, so I am at a loss as to why it would appear to be running out of IDs. Should I be deleting/cleaning up sounds somewhere?
The only other sound in the game is an explosion sound, which also suffered from the same error but only once and has never done it again.

Any advice would be much appreciated.

The author of this post has marked a post as an answer.

Go to answer

JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 17th Nov 2018 18:42
Are you only loading the sound once or do you have t inside the game loop?
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 17th Nov 2018 20:05
The sound is only loaded once to the constant outside of the main loop.
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 17th Nov 2018 20:20
Try changing it from a #constant, to a global variable.
GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 17th Nov 2018 20:45
That gives me a compilation error of "Variable default value must be an integer literal or constant"

I have however just tried a different approach. I set lasersnd as an array and loaded the sound into position 1.
Just completed approx. 1500 shots fired and no crash so seems like it might be fixed. Interestingly at 1500 or so it crashed again with the same error for the 'explosion' sound I handled in the same way so I'm guessing that had just hit the mid 200s too (an appalling hit rate on my part ). I'll change that to use an array of sounds too.
Actually is a nicer approach as I can dispense with the Case statement I was going to use to play the relevant sound and just use the weapon variable passed to my function as the sound array index.

Thanks

Graham
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 17th Nov 2018 21:32
It is important to remember that AppGameKit will "paste" that value into the code when it is referenced so when compiled;

createshot(lasersnd,1,player.x,player.y-20,player.x,player.y-500,laserspd,laser,laserimg)
will look like;

createshot(LoadSound("laser.wav"),player.x,player.y-20,player.x,player.y-500,laserspd,laser,laserimg)

So every time you reference createshot() that sound will be loaded
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 18th Nov 2018 09:43 Edited at: 18th Nov 2018 09:47
This post has been marked by the post author as the answer.
Quote: "That gives me a compilation error of "Variable default value must be an integer literal or constant""



global variables must be defined like so




but as mentioned above you are loading the sound each time you fire a shot, this will consume all available id's and memory.... eventually!

this is how you should use the variable


now in your trigger function you use the variable of the already loaded sound over and over without any problems.



GH69
5
Years of Service
User Offline
Joined: 9th Nov 2018
Location:
Posted: 18th Nov 2018 16:16 Edited at: 18th Nov 2018 16:16
Cheers for the help guys.

So by swapping to using an array of weapon sounds I inadvertently hit the right way of defining my variable.

Thanks again.

Login to post a reply

Server time is: 2024-04-19 21:38:49
Your offset time is: 2024-04-19 21:38:49