Computer Science Canada Need help going "backwards" with multiple procedures.. |
Author: | mooki3 [ 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!!
Please specify what version of Turing you are using The latest version |
Author: | RandomLetters [ 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 |
Author: | mooki3 [ 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 |
Author: | RandomLetters [ 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. |
Author: | RandomLetters [ 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 |
Author: | mooki3 [ 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 |
Author: | Wakening [ 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.
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)
Some more info about case: http://compsci.ca/holtsoft/doc/case.html |
Author: | Dreadnought [ 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.
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 |
Author: | Raknarg [ 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.
Anyways, just a little tip, if its useful in any way. However, I would considers Dreadnaught's idea. |