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 DBPro Corner / cean up my code?

Author
Message
james863484
10
Years of Service
User Offline
Joined: 21st Sep 2013
Location:
Posted: 29th Sep 2013 05:29
i was playing around with a mp3 player type program. i started off by using the load music command and realized that in in order to load a number of mp3's i needed to use load music command for each mp3. is there any way to load multiple files using same command. same issue when programing function for keys using if then command. example;

if keystate (80) =1 then play music 1
if keystate (80) =1 then stop music 2
if keystate (80) =1 then paste image 1,100,100,0

so on and on. I would like to accomplish all with single if keystate statement. can any one help?

thanks james863484
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 29th Sep 2013 09:39
Quote: "is there any way to load multiple files using same command."

No, although if the names follow a set pattern, you might be able to use a loop to iterate over them and load them.

Quote: "I would like to accomplish all with single if keystate statement."

Sure, you can do that like this.



Basically you just drop the "then" and put an endif at the end of the block.

Hope that helps.

james863484
10
Years of Service
User Offline
Joined: 21st Sep 2013
Location:
Posted: 29th Sep 2013 20:19
thanks Lucas using the if and enif helped a lot and made my code much more organized.

"No, although if the names follow a set pattern, you might be able to use a loop to iterate over them and load them."

using a loop to load though is beyond me at the moment. any resources you can point me to that would help me understand this would be appreciated.
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 29th Sep 2013 21:47
Quote: "i started off by using the load music command and realized that in in order to load a number of mp3's i needed to use load music command for each mp3"


@Lucas Tiridadth
I had the same problem when I made my material editor...I had to load them all at once. So it is possible with this example code...put this piece of code where you have some images, and the code will open all of them (bmp or jpg) we could even add .tga .3ds .dbo every media we need, all at once .





Cheers.

I'm not a grumpy grandpa
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 1st Oct 2013 02:36
Quote: "
if keystate (80) =1 then play music 1
if keystate (80) =1 then stop music 2
"


This won't really do much for ya. It's going to play then immediately stop. Sometimes it might play, sometimes you might not hear anything, depends on when you release the button. You need to use what's referred to as a flag so that the IF statement doesn't keep calling that code segment while the button is being held down.




Indicium
15
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 2nd Oct 2013 22:34
Phaelax didn't look at the numbers.


They see me coding, they hating. http://indi-indicium.blogspot.co.uk/
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Oct 2013 08:48
Ooo I see. That still isn't the best way though. Making 3 IF statements where only 1 is needed.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Oct 2013 13:36 Edited at: 3rd Oct 2013 13:42
Maybe you could just check if the music is playing, like if music 1 is playing, do nothing, otherwise stop music 2 and play music 1.

If keystate(80)=1
if music playing(1)=0 then play music 1 : stop music 2
paste image 1,100,100,0
Endif

Also, that would only show the image while you press the key, if you want to show the image the whole time, then it might be better to use a sprite instead, that way it'll stay there and be drawn each loop without you having to do anything.

But anyway, I would suggest that you just have 2 music ID's and switch between them when changing tracks. Like, load the new track into the non-playing slot, then fade the old music volume and start the new music. It probably doesn't take too long to load an MP3, so it's not like you have to load every MP3 in advance, having just 2 music tracks at a time would keep the memory requirements down.
Endif

I am the one who knocks...

Login to post a reply

Server time is: 2024-04-20 15:38:51
Your offset time is: 2024-04-20 15:38:51