Need help going "backwards" with multiple procedures..
Author |
Message |
mooki3
|
Posted: Wed Jan 04, 2012 8:44 pm Post subject: Need help going "backwards" with multiple procedures.. |
|
|
I have a project where it involves multiple procedures ("Sections", it is a tutorial and there are different topics and I have a table of contents, which is why I have the multiple procedures)
What is it you are trying to achieve?
I want to go "backwards" a "slide" (Go back to a previous procedure)
What is the problem you are having?
The order matters for procedures, so sometimes it will not be able to read the procedure because of the order
Describe what you have tried to solve this problem
I have no clue how to solve this problem
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
notice how i am able to go to slide2, but not slide3 because of the order (look at green %)
If I put slide3 instead of slide2, it will show that slide3 is not declared.
How can I make it so slide3 is accessible when i put a button saying "go back to slide3"?
THANKS FOR HELPING!!
Turing: |
procedure slide2
cls
put "hi again"
Time.Delay (1000)
end slide2
procedure slide1
put "hi"
Time.Delay (1000)
%slide2
end slide1
procedure slide3
put "hi"
Time.Delay (1000)
end slide3
var answer : string (1)
put "Press any button to start the study guide.."
getch (answer )
cls
slide1
|
Please specify what version of Turing you are using
The latest version |
|
|
|
|
|
Sponsor Sponsor
|
|
|
RandomLetters
|
Posted: Wed Jan 04, 2012 8:53 pm Post subject: RE:Need help going "backwards" with multiple procedures.. |
|
|
why not move slide 3 up above
everything in turing has to be declared before that line, before it can be used |
|
|
|
|
|
mooki3
|
Posted: Wed Jan 04, 2012 8:54 pm Post subject: Re: Need help going "backwards" with multiple procedures.. |
|
|
there are more than 3 slides, so simply moving it up won't solve the problem. each slide has a "next" and "back" button |
|
|
|
|
|
RandomLetters
|
Posted: Wed Jan 04, 2012 8:58 pm Post subject: RE:Need help going "backwards" with multiple procedures.. |
|
|
then you can use forward declarations, to let turing know you want to use it. although I dont remember the syntax, sorry. |
|
|
|
|
|
RandomLetters
|
Posted: Wed Jan 04, 2012 9:06 pm Post subject: RE:Need help going "backwards" with multiple procedures.. |
|
|
alternatively, I see that there is repeition, so a single proc might also work.
proc newSlide(text : string)
cls
put(text)
delay(1000)
end newSlide |
|
|
|
|
|
mooki3
|
Posted: Wed Jan 04, 2012 9:11 pm Post subject: Re: Need help going "backwards" with multiple procedures.. |
|
|
how will a single proc work? sorry i'm not that great at turing |
|
|
|
|
|
Wakening
|
Posted: Wed Jan 04, 2012 10:51 pm Post subject: Re: Need help going "backwards" with multiple procedures.. |
|
|
What I think would be more organized than simply nesting procedures inside each other would be to use case. Have a variable that decides the slide number to display that would increase or decrease by one depending on next or back.
code: |
var slidenum : int := 0
if next = true then
slidenum += 1
elsif back = true then
slidenum -= 1
end if
|
Then use case, so that every time a slide is turned, the program scans through all the possible slides and selects the one required (the one after/before the current slide)
code: |
case slidenum of
label 1 : slide1
label 2 : slide2
label 3 : slide3
end case
|
Some more info about case:
http://compsci.ca/holtsoft/doc/case.html |
|
|
|
|
|
Dreadnought
|
Posted: Wed Jan 04, 2012 11:22 pm Post subject: Re: Need help going "backwards" with multiple procedures.. |
|
|
Here's an example of how a single general procedure can be useful.
Turing: | proc DrawRectangle % A procedure with static values
Draw.Box(100, 100, 500, 350, 7) % Draw a black, 400x250 rectangle at 100,100
end DrawRectangle
proc DrawBetterRectangle (Xoffset, Yoffset, Width, Height, Colour: int) % A procedure with dynamic values (we call these parameters)
Draw.Box(Xoffset, Yoffset, Xoffset + Width, Yoffset + Height, Colour ) % This draws a rectangle with a width and a height, nothing fancy
end DrawBetterRectangle
put "DrawRectangle"
DrawRectangle
Time.Delay(2000)
cls
Time.Delay(200)
put "DrawBetterRectangle(100,100,400, 250,7)"
DrawBetterRectangle (100, 100, 400, 250, 7) % This draws the same rectangle as DrawRectangle
% In this particular case
% Xoffset = 100
% Yofffset = 100
% Width = 400
% Height = 300
% Colour = 7 (black)
Time.Delay(2000)
cls
put "But now we can also create a different rectangle."
Time.Delay (1000)
put "DrawBetterRectangle (50,90,100,250,12)"
DrawBetterRectangle (50, 90, 100, 250, 12) |
See how the "better" procedure has an output that changes with the input. This means we don't have to make a new procedure for each new rectangle.
RandomLetters's procedure is a general procedure that outputs a string to the screen. If you had an array of strings, then you could easily go from one to the next by adding or subtracting one from the subscript, using a loop to call the procedure again with the new argument (input).
Here's a good tutorial that does a better job of explaining functions and procedures http://compsci.ca/v3/viewtopic.php?t=14665 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Thu Jan 05, 2012 3:49 pm Post subject: RE:Need help going "backwards" with multiple procedures.. |
|
|
I have another solution, if you want to try it out.
You can create an array of procedures. Hopefully you already know a bit about them; If so, this will be useful.
You call it like this:
var foo : array 1 .. 3 of proc x
I say proc x because there has to be some kind of variable next to it. I don't think it matters what it is. Just put something there.
Now for you to use this, you call all your procedures and then assign it to an array. That way, you can call a procedure simply by using a number.
Turing: |
var slides : array 1 .. 3 of proc x
procedure slide1
put "hi"
Time.Delay (1000)
%slide2
end slide1
slides (1) := slide1
procedure slide2
cls
put "hi again"
Time.Delay (1000)
end slide2
slides (2) := slide2
procedure slide3
put "hi"
Time.Delay (1000)
end slide3
slides (3) := slide3
|
Anyways, just a little tip, if its useful in any way. However, I would considers Dreadnaught's idea. |
|
|
|
|
|
|
|