Computer Science Canada How do you use a variable declared in a procedure in another procedure |
Author: | 1kd7 [ Wed Oct 01, 2014 1:50 pm ] | ||
Post subject: | How do you use a variable declared in a procedure in another procedure | ||
What is it you are trying to achieve? Im trying to use a variable declared in a procedure in another procedure. What is the problem you are having? Its not recognizing it as a declared variable. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using 4.1.1 |
Author: | Tony [ Wed Oct 01, 2014 2:09 pm ] | ||
Post subject: | RE:How do you use a variable declared in a procedure in another procedure | ||
It's a matter of scope, and it's a good thing --in a multi-million lines projects (e.g. web browsers, operating systems, etc.) you wouldn't want your "count" variable to interfere with many other similarly named variables. In your case, the variable can be declared outside of the procedure first to get a larger scope (bad design, one typically wants to limit the scope of variables), or have the procedure return the value, becoming a function. I also suspect that your RollDie, RollDie2, RollDie3, and RollDie4 are just copy-pasted code, with some values changed around. You could combine them all into a single function, and use an argument for those minor changes.
|