Computer Science Canada

Turing Play music, is loop really needed?

Author:  kha.andrew [ Sun Jun 04, 2006 2:12 am ]
Post subject:  Turing Play music, is loop really needed?

Quote:
process DoMusic
loop
Music.PlayFile ("branden3.wav")
end loop
end DoMusic

fork DoMusic


This is the standard code to play a music file.

But is the loop really needed?
won't it work just like this?:
Quote:
process DoMusic

Music.PlayFile ("branden3.wav")

end DoMusic

fork DoMusic


I'm also doing a program for school and I need to have a nested loop(loop in a loop), right now I have no ideas.. anyone else have any idea?

Author:  kha.andrew [ Sun Jun 04, 2006 2:16 am ]
Post subject: 

lol, forgot to tell you what program I making.
I am making a program that has information in it. Mainmenu, submenus with info, Quiz to see what you learned, etc.

...you need to add the EDIT button for the posts, so I can add in stuff if I forget, so I don't double post.

Author:  TheOneTrueGod [ Sun Jun 04, 2006 8:09 am ]
Post subject: 

Part of the reason to remove the edit button (IMO) was so people would think about what they were posting before posting it, thereby eliminating some of the more pointless questions.

Of course, thats just speculation. The answer I got was "Mods don't like you and we feel like having something above you" Razz

Anyways, onto your question.

The two will both work, but one will replay the music when the song ends, and one won't (I think you can figure out which is which). You could allways just use Music.PlayFileReturn (I think thats what its called... Razz) if its in your version of Turing, and I believe there is a looped version of it.

Author:  Cervantes [ Sun Jun 04, 2006 8:19 am ]
Post subject:  Re: Turing Play music, is loop really needed?

kha.andrew wrote:
I'm also doing a program for school and I need to have a nested loop(loop in a loop), right now I have no ideas.. anyone else have any idea?

A nested loop would look like this:

code:

loop
    %do something
    loop
        %do something
    end loop
    %do something
end loop

You would quite likely require something like that for a program with a main menu. The outer loop is for the main menu, and the inner loop(s) is for the thing you chose to run from the main menu.

Of course, this would all be much better if you split the code up with subroutines: Procedures and Functions. Check the Turing Walkthrough for a link to a tutorial on them.

Author:  kha.andrew [ Sun Jun 04, 2006 12:28 pm ]
Post subject:  Re: Turing Play music, is loop really needed?

Cervantes wrote:


code:

loop
    %do something
    loop
        %do something
    end loop
    %do something
end loop

You would quite likely require something like that for a program with a main menu. The outer loop is for the main menu, and the inner loop(s) is for the thing you chose to run from the main menu.

Of course, this would all be much better if you split the code up with subroutines: Procedures and Functions. Check the <a href="http://www.compsci.ca/v2/viewtopic.php?t=8808">Turing Walkthrough</a> for a link to a tutorial on them.



I don't have loops like that. All my menus and submenus are coded as procedures and they are called with a huge list of ifs set at the bottom.

the only loop I have is the loop for the ifs


code:

procedure ....
%Do something
%Do something
end ....

procedure ....
%Do something
%Do something
end ....

loop

if ...
then
%Do something
elsif...
then...
%Do something
end if..

if ...
then
%Do something
elsif...
then...
%Do something
end if..

if ...
then
%Do something
elsif...
then...
%Do something
end if..

end loop


: