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

Username:   Password: 
 RegisterRegister   
 How does turing handle/interpret text files?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Recoil




PostPosted: Mon Jan 19, 2004 9:23 pm   Post subject: How does turing handle/interpret text files?

semester's almost over, and ill be starting commtech 11 (java!) in a few weeks, so i thought i'd brush up on my turing skills for practice, and maybe start my java ISU in turing, and port it over later.

so im making a platformer, (if you must know, based on that oh-so-holy FPS HALO ) and have got pretty much everythng worked out (i've made a smaller-scale platformer before, so the actual mechanics are no problem for me)

the problem comes in implementing turing's open/get through external text files.. here's how its layed out so far...

the plan is to have the screen set up as a 640x480 (scaling will be implemented later on) window, split up into 16x16 tiles, Mario Style. therefore, a two-dimensional array, layer1 which is 40x30.

what i want to end up with, is a text file like so:
code:

0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000322222230000000000000
0000000000000000000111111110000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000422222222222222222222222222
2222222222222311111111111111111111111111
1111111111111111111111111111111111111111

(as an example of a single screen, with a gradually sloping ground and island about 2/3 to the right) each value represents what that tile will be in-game, 0 being sky, 1 being solid ground, 2 being grass, etc.

i want turing to open this file, and line by line distribute each number into the array, based upon its position in the textfile. from there, the game can already handle it.

but so far, the only way i've been able to do it is by putting each number on its own line... ie:
code:

0
0
0
0
0
0
0

...etc, 1200 lines down.

the code for this is:
code:

procedure loadlevel
open : fileNo, fileNa, get
for decreasing y : 30..1 %every row, for 30 rows..
for x : 1..40 %do the following for 40 columns
get : fileNo, data % gets the data from your file
layer1 (x,y) := strint (data) % store the data in layer1, strint is used because the text file is normall read as a string, we want it as integers 
exit when eof (fileNo) % exit the for loop when there is nothing more to read
end for
exit when eof (fileNo) % exit the for loop when there is nothing more to read
end for
close (fileNo) % close the file

if checkleveldata = 1 then %for testing purposes
put "dump of ",fileNa," : "
for y : 1..30
for x : 1..40
put layer1 (x,y)..
end for
View.Update
delay (50)
put ""
end for
delay (2000)
end if

end loadlevel


but i just *can't* get it to read each row and THEN split it up and distribute to the array.

its just totally wracking my brain... please help Crying or Very sad

i've attached a zip of the entire directory... if you want to see how it is supposed to work in the end, open up and run leveleditor, and when it asks for a file, tell it to use "level1.txt"..but open up level1.txt in notepad, and see how it is 1200 lines :/ .... what i want to use in the end is something like level1a.txt .....

thanks for the help Smile



Platformer2.zip
 Description:

Download
 Filename:  Platformer2.zip
 Filesize:  5.77 KB
 Downloaded:  127 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Mon Jan 19, 2004 9:36 pm   Post subject: (No subject)

well to get one character in Turing use:

get:fileNo, data:1

I think from what I see in your code you'll figure it out from here. (The colon forces character-based rather than token based input so it does not skip over whitespace before getting data)
- oh data had better be string. (use strint later if you want int)
Recoil




PostPosted: Mon Jan 19, 2004 10:29 pm   Post subject: (No subject)

and w00t, it works... awesome... thanks man..

didn't work at first (passed illegal character to strint), then realized it was counting carriage returns, and i changed the column forcount to 41 (insted of 40) and told it to skip over passing it into the array when the count was 41...

thanks alot

code:

procedure loadlevel
open : fileNo, fileNa, get
for decreasing y : 30..1 %every row, for 30 rows..

for x : 1..41 %do the following for 40 columns
get : fileNo, data :1  % gets the data from your file
if x < 41 then
layer1 (x,y) := strint (data) % store the data in layer1, strint is used because the text file is normall read as a string, we want it as integers
end if
exit when eof (fileNo) % exit the for loop when there is nothing more to read
end for
exit when eof (fileNo) % exit the for loop when there is nothing more to read
end for
close (fileNo) % close the file

if checkleveldata = 1 then
put "dump of ",fileNa," : "
for y : 1..30
for x : 1..40
put layer1 (x,y)..
end for
View.Update
delay (50)
put ""
end for
delay (2000)
end if
end loadlevel

so just to be clear... when turing *normally* gets anything from say a textfile, it stops at a space right? and skips over all spaces, going to the next "word" ? and doesn't count carriage returns as a word, but does count them as characters... just being 100% sure here...
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  [ 3 Posts ]
Jump to:   


Style:  
Search: