Using arrays in a procedure
Author |
Message |
amy616
|
Posted: Fri Nov 12, 2010 9:30 am Post subject: Using arrays in a procedure |
|
|
What is it you are trying to achieve?
I'm trying to use array variables in a procedure.
The game I'm trying to make is a SUDOKU game, so I want to have about 1~81 variables for each square.
What is the problem you are having?
(procedure sudoku (x, y, locatex, locatey : int, num : array 1 .. 81 of int))
is my first code, and the num:array 1..81 of int does work, but when ever I wish to give the num(x) variable a value like 2 or 5
(num := value)
it says that the left side is not a variable and it cannot work.
Also, my line that makes the procedure work, ( sudoku (xcounter, ycounter, 35, 25, num (73)))
will say that the num(73) is "Argument is the wrong type".
Describe what you have tried to solve this problem
I tried the game without the num(x) array variables and it works fine. When I don't have the num:=value line, it worked as well.
I tried saying (var num : array 1 .. 81 of int) instead, but it didn't work.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
var xcounter, ycounter : int := 0
var num : array 1 .. 81 of int
for x : 1 .. 81
num (x ) := 0
end for
procedure sudoku (x, y, locatex, locatey : int, num : array 1 .. * of int)
var button : string (1)
locate (1, 1)
put "Type in number"
getch (button )
num := button
locatexy (locatex, locatey )
put button
end sudoku
loop
mousewhere (xcounter, ycounter, click )
if xcounter > 0 and xcounter < 60 and ycounter > 0 and ycounter < 50 and click = 1 then
sudoku (xcounter, ycounter, 35, 25, num (73))
elsif xcounter > 60 and xcounter < 120 and ycounter > 50 and ycounter < 100 and click = 1 then
sudoku (xcounter, ycounter, 100, 84, num (65))
end if
|
Please specify what version of Turing you are using
It says 411... so I think it is 4.1.1 version. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Fri Nov 12, 2010 12:05 pm Post subject: RE:Using arrays in a procedure |
|
|
You cannot assign a value to the whole array. You mean to say:
which will set the second element of the array to 5.
Similarly, if your method expects you to pass it an array, you cannot very well pass it an integer and expect it to be happy about it. Pass it the whole num array, as follows:
code: | sudoku (xcounter, ycounter, 35, 25, num ) |
Granted, none of this says anything about the wisdom of your approach. You may want to think for a good long while about exactly how your approach is going to work before programming it. It sucks to get halfway through and realize you missed something big. |
|
|
|
|
|
|
|