Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 File reading difficulties
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: 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.
Raknarg




PostPosted: Mon Jul 18, 2011 7:20 pm   Post subject: RE:File reading difficulties

I'm sorry, I really just don't get it -.-'
Tony




PostPosted: 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)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Tue Jul 19, 2011 7:29 pm   Post subject: RE:File reading difficulties

Whoops, found my mistake it was a logic error.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: