Computer Science Canada reading/writing |
Author: | Bunny_Man_OC [ Mon Dec 25, 2006 1:51 am ] |
Post subject: | reading/writing |
im making a game on turing, and i need to draw a line behinde my ship, but the line isn't exactly... permannent, so i decided to right the directions the ship goes to a file... but i need to read it as well... if i close the file so i cna read it, then it will right over hwat whas written befor,e and it wont work properly. is there a way to have it read and write to a file at the same time?? or maybe transfer teh contents of one file to another, so that i can read from the new file, w/o having to close teh old file?? any help or otehr idea's would be appreciated ![]() |
Author: | Cervantes [ Tue Dec 26, 2006 9:47 am ] | ||
Post subject: | |||
It is possible to open a file and append information to it. Do it like this:
You could perhaps also do some tricks with File.Copy. However, I wonder if using a file is the best idea. Why not just store your information in a (flexible) array? What does the data look like. Is it really really big? |
Author: | Bunny_Man_OC [ Tue Dec 26, 2006 3:54 pm ] | ||||
Post subject: | |||||
Cervantes wrote: It is possible to open a file and append information to it. Do it like this:
You could perhaps also do some tricks with File.Copy. However, I wonder if using a file is the best idea. Why not just store your information in a (flexible) array? What does the data look like. Is it really really big? the data is stored as a string, I store the direction that the ship has moved. i tried to make an array and store the direction to an array. but the array would have to add subscripts to itself... and i didn't kow how to add one to it, so i was put using a counter and declaring an array every time an acion was taken. and then giving it a value .
i really wasn't sur eif that was a good idea, and figured it would probably flood the program with variables... or if it did work, that it would delete the previous entries, and make a new array, and only write data rto the last slot. so i figured that using a dat file and writng information to it would be the best way to do it. then i could write the direction taken, and read it later so i could draw (from the ships starting point) a line in every directiuon it took. (since the ship moves "speed" pixels in one direction every move) |
Author: | Bunny_Man_OC [ Tue Dec 26, 2006 3:56 pm ] | ||
Post subject: | |||
Cervantes wrote: It is possible to open a file and append information to it. Do it like this:
You could perhaps also do some tricks with File.Copy. However, I wonder if using a file is the best idea. Why not just store your information in a (flexible) array? What does the data look like. Is it really really big? i tried the seek thing, and it keeps saying "put attempted on incompatable stream number 1" so i must have done something wrong... ![]() |
Author: | Cervantes [ Tue Dec 26, 2006 4:12 pm ] |
Post subject: | |
You should learn how to use flexible arrays. That oughta solve all your problems, I think. |
Author: | Bunny_Man_OC [ Wed Dec 27, 2006 7:39 pm ] |
Post subject: | |
Cervantes wrote: You should learn how to use flexible arrays. That oughta solve all your problems, I think.
thanks for the help ![]() ![]() |
Author: | [Gandalf] [ Wed Dec 27, 2006 7:46 pm ] |
Post subject: | |
Woah woah woah... Flexible multi dimensional array? You're bound to run into more than a few problems with that, seeing as how Turing's support of such arrays is limited/non-existent. Why exactly do you need an array with multiple dimensions in the first place? |
Author: | Bunny_Man_OC [ Wed Dec 27, 2006 9:03 pm ] |
Post subject: | |
[Gandalf] wrote: Woah woah woah... Flexible multi dimensional array? You're bound to run into more than a few problems with that, seeing as how Turing's support of such arrays is limited/non-existent. Why exactly do you need an array with multiple dimensions in the first place?
well, i'm usig the array to draw a line on the screen. each subscript will equal a direction, and i'll us the directions to draw the line out. this line is technically temporary, but when the ship touches a boarder, it becomes permanent, so i can use a multi dimentional array for drawing a new line. he said you can change one of the upper bounds, as long as you leave the otehr one alone, so tahts what I'll do. and this way I can draw out a bunch of different lines. unless someone can think of a better way to do this. i thought it seemed logical, but i guess there might be an easier way to do it. but since i redraw the playing grid every loop, i need something like this to ensure all of the lin is srawn again (since the line might be odd hsapes and not just one big line from point a to b) |
Author: | Clayton [ Wed Dec 27, 2006 10:01 pm ] |
Post subject: | |
Why not use records? that way you can keep a flexible array of coordinates for each of the lines, that way you don't have to worry about a second dimension. Check for the tutorial in the Turing Walkthrough |
Author: | Bunny_Man_OC [ Wed Dec 27, 2006 10:07 pm ] |
Post subject: | |
Freakman wrote: Why not use records? that way you can keep a flexible array of coordinates for each of the lines, that way you don't have to worry about a second dimension. Check for the tutorial in the <a href="http://www.compsci.ca/v2/viewtopic.php?t=8808">Turing Walkthrough</a>
i guess I can try that out... but ive never quite understood how to use records all that well, so i guess a tutorial on em wouldn't be that bad of an idea right now ![]() |