File reading difficulties
Author |
Message |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Mon Jul 18, 2011 6:38 pm Post subject: File reading difficulties |
|
|
I'm trying to make a tower defence game. For the map, I've read about using text files, so i'm trying to do that. I read the tutorial, but I don't think I'm getting it. Here's what I have:
1. a text file like this:
00001000000000000000
00001000000000000000
00001000000000000000
00001000000000000000
00001111111111110000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00000000000000010000
00001111111111110000
00001000000000000000
00001000000000000000
00001000000000000000
1 = path
0 = building area
2. I have a little bit of code im trying to use:
Turing: |
var num1, num2 : int := 1
var stream : int
var myText : array 1 .. 20, 1 .. 20 of string
open : stream, "path.txt", get
loop
exit when eof (stream )
get : stream, myText (num1, num2 )
num1 + = 1
if num1 div 20 = num1 / 20 then
num2 + = 1
end if
end loop
|
It tells me later on that variable has no value when I try to use the array, so I know its not assigning any values.
I've never done file reading before, so im confused ![Razz Razz](http://compsci.ca/v3/images/smiles/icon_razz.gif) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Mon Jul 18, 2011 7:04 pm Post subject: RE:File reading difficulties |
|
|
Your get line is wrong. Look at it very carefully and try to figure out what's going to be put into your array at (1,1). Once you figure that out, you should know exactly what's happening, and you can look at the Turing help for the get command to learn how to solve it. |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Mon Jul 18, 2011 7:20 pm Post subject: RE:File reading difficulties |
|
|
I'm sorry, I really just don't get it -.-' |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jul 18, 2011 8:01 pm Post subject: RE:File reading difficulties |
|
|
code: |
put "trying to read into (", num1, ", ", num2, ")"
get : stream, myText (num1, num2)
put "read: ", myText (num1, num2)
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Tue Jul 19, 2011 7:29 pm Post subject: RE:File reading difficulties |
|
|
Whoops, found my mistake it was a logic error. |
|
|
|
|
![](images/spacer.gif) |
|
|