Procedures and arrays
Author |
Message |
challenger
|
Posted: Sat Jan 16, 2010 3:38 pm Post subject: Procedures and arrays |
|
|
sorry, messed up post before
What is it you are trying to achieve?
Get better understanding of procedures and arrays
What is the problem you are having?
how do you store the value of something in the procedure in an array with the mouse input
Describe what you have tried 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)
Turing: |
procedure buttonzero
put "0"
end buttonzero
procedure buttonone
put "1"
end buttonone
var zero : int := GUI.CreateButton (, 250, 0, "0", buttonzero )
var one : int := GUI.CreateButton (200, 200, 0, "1", buttonone )
%how do i program it so whenever i click either 0 or 1 it will store it in an array.
%ex. i click 1 then 0, so it displays 10 ( 0 in the zero index and 1 in the first index)
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Prince Pwn
|
Posted: Sun Jan 17, 2010 4:21 pm Post subject: Re: Procedures and arrays |
|
|
First, create an array like such and an index counter starting at 0
Turing: |
var binaryArray : array 1 .. 10 of int
var currentIndex : int := 0
|
Instead of using 'put' which displays the '1' or '0' to the screen, store it in the array.
Turing: |
procedure buttonzero
binaryArray (currentIndex ) := 0
end buttonzero
procedure buttonone
binaryArray (currentIndex ) := 1
end buttonone
var zero : int := GUI.CreateButton (200, 250, 0, "0", buttonzero )
var one : int := GUI.CreateButton (200, 200, 0, "1", buttonone )
|
To keep track of the current index, use a counter and increase it each time you click a button.
You can then use a for loop to display the array.
Turing: |
for i : 1 .. length (binaryArray )
put binaryArray (i )
end for
|
|
|
|
|
|
|
|
|