Posted: Wed Jan 04, 2012 8:36 pm Post subject: going backwards with multiple procedures..
delete this topic please, was posted on the wrong forum
mod edit: moved to Turing Help since there are already a few replies with content.
Sponsor Sponsor
Insectoid
Posted: Wed Jan 04, 2012 8:45 pm Post subject: RE:going backwards with multiple procedures..
'going back' is simply ending the procedure. If slide 1 calls slide 2, and slide 2 ends, slide 1 will continue at the next line of code. Basically, it will look like this:
code:
proc slide1
loop
if (next button pushed)
slide2
else if (back button pushed)
quit slide1
end if
end loop
end slide1
Of course, if you have 500 slides you'll end up with a procedure in a procedure in a procedure, etc. And then your computer will eventually give up.
A better way would be to use functions instead of procedures and return the number of the slide to go to. You have a main procedure that runs slide1, then slide1 will run until 'back' or 'next' is clicked. If 'next' is clicked, slide1 will return 2, then the main proc will run procedure 2. If 'back' is clicked, slide1 will return 0, and the main proc will quit. Similarly, slide2 will return 3 if 'next' is clicked, and 1 if 'back' is clicked. This way, only 2 procedures are ever running at the same time- the main proc, and a slide. This method will also greatly simplify adding extra controls. For example, you could add functionality to enter a slide number and instantly go to that slide.
mooki3
Posted: Wed Jan 04, 2012 8:57 pm Post subject: Re: going backwards with multiple procedures..
I'm not that familiar with functions, I've always used procedures simply because they are easier to make.
Can you please give me an example of how to do it with functions? A basic outline of 3 slides would be great
Thanks for being so helpful!!
Insectoid
Posted: Wed Jan 04, 2012 9:03 pm Post subject: RE:going backwards with multiple procedures..
Functions are exactly like procedures, except they return a value.
code:
function foo (a:int) : int //this function returns an integer
result 2*a // 'result' ends the function and returns a value. In this case, we just return 2*a
end foo
int bar = foo (5)
put bar //output will be 10
EDIT: My Turing's a bit rusty so the syntax might be a bit off.
Zren
Posted: Wed Jan 04, 2012 9:57 pm Post subject: Re: RE:going backwards with multiple procedures..
Insectoid @ Wed Jan 04, 2012 9:03 pm wrote:
Functions are exactly like procedures, except they return a value.
Turing:
function foo (a:int):int%this function returns an integer result2*a % 'result' ends the function and returns a value. In this case, we just return 2*a end foo
var bar := foo (5) put bar %output will be 10
EDIT: My Turing's a bit rusty so the syntax might be a bit off.