Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help with fork command.. possibly?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Krol23




PostPosted: Mon Jun 13, 2011 6:12 pm   Post subject: Need help with fork command.. possibly?

What is it you are trying to achieve?
Hi there. I am trying to play an mp3 file when my frog clears a stage in the frogger game I have created but having some troubles; please help.


What is the problem you are having?
My song file plays first, and then the screen is cleared and my Draw.Font text is displayed after, whereas I want both of these things to happen simultaneously.


Describe what you have tried to solve this problem
I have tried messing around with processes, procedures, and the fork command but I don`t really know what I`m doing.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Basically I'm saying that when the coordinates of my frog character collide with the colour 54 then the screen is cleared, and my font is displayed saying "success" and such. However the music is played before all of this while still in game. I want the screen to be cleared, my font to be displayed, and the music to play all at the same time. Please note that my "failure:= true" is simply so that an irrelevant loop is exited when the frog reaches colour 54.

Turing:

        elsif whatdotcolour (xcounter, ycounter) = 54 then
            cls
            failure := true
            Font.Draw ("Success!", 300, 400, endfont, white)
            Font.Draw ("Press F1 to play again.", 300, 380, endfont, white)
            Music.PlayFile ("stage_completed.mp3")
            exit

        end if



Please specify what version of Turing you are using
Version 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Jun 13, 2011 6:23 pm   Post subject: RE:Need help with fork command.. possibly?

Create a process for the music instead of calling it directly.

code:
process playMusic (musicFile : string)
    Music.PlayFile (musicFile)
end playMusic

%now, any time you want music, just fork playMusic()
fork playMusic ("stage_completed.mp3")


You can also use Music.PlayFileLoop(), but I think this, as obviously implied, loops the music, therefore requiring Music.PlayFileStop() to, well, stop it. That can get very inconvenient if you're playing lots of files of variable length, so just stick with the process approach.
Tony




PostPosted: Mon Jun 13, 2011 7:09 pm   Post subject: RE:Need help with fork command.. possibly?

Arguably a better way of doing it is to use a non-blocking Music.PlayFileReturn
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Krol23




PostPosted: Mon Jun 13, 2011 8:16 pm   Post subject: Re: Need help with fork command.. possibly?

Thanks for you help guys, but I'm still stuck. Now I'm forking the music and I have the same problem. The screen is only cleared and "success" is only printed when the mp3 file finishes playing. I have also made additions so that my background music during gameplay stops when the frog collides, but I'm not having problems with that.

My process for the music that is to play when the frog collides is simply this:

process complete
Music.PlayFile ("stage_completed.mp3")
end complete

And here is my new code:

Turing:

        elsif whatdotcolour (xcounter, ycounter) = 54 then
            cls
            finished := true
            Music.PlayFileStop
            failure := true
            Font.Draw ("Success!", 300, 400, endfont, white)
            Font.Draw ("Press F1 to play again.", 300, 380, endfont, white)
            fork complete
            exit
        end if




Any help is greatly appreciated. Again, all I need is everything above to occur at the same time. Thanks.
Tony




PostPosted: Mon Jun 13, 2011 8:26 pm   Post subject: RE:Need help with fork command.. possibly?

Are you using offscreenonly? If so, you might have forgotten to update the screen.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Krol23




PostPosted: Tue Jun 14, 2011 6:45 am   Post subject: Re: Need help with fork command.. possibly?

I am using offscreenonly, Tony. Where might I have to throw a view.update in there to get this to work?
Krol23




PostPosted: Tue Jun 14, 2011 6:58 am   Post subject: Re: Need help with fork command.. possibly?

Nevermind actually, I put a View.Update in and got everything to work properly. Thanks very much for your help Tony
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: