Computer Science Canada Reading Text Files |
Author: | Hack.saw [ Fri Jun 16, 2006 9:57 am ] |
Post subject: | Reading Text Files |
Hehe half my posts are me asking for help... Anyway I saw a game where every class of the RPG had its stats or w/e written down in text documents which turing read. Sooo I set to reading the tutorial on it but all it did was give me a head ache ![]() |
Author: | Delos [ Fri Jun 16, 2006 11:47 am ] |
Post subject: | |
Only 30? That's no good. Anyway, please post up your code so we know where to start. It's not use anyone giving you 'step-by-step' instructions starting from the definition of a variable downwards if you already know that stuff. Conversely, starting from the definition of an input stream might confuse you too - it all depends on how far you've progressed. We'll only know this from your code. As for the Tut by Dan, I don't see anything wrong or confusing with that Tut. It's about as step-by-step as you can get! |
Author: | Hack.saw [ Fri Jun 16, 2006 3:57 pm ] | ||
Post subject: | |||
LOL, just deleted all the code cause i figured i must have done something wrong a couldnt find, so i was gona try and start over from scratch, anywho his tut wasnt confusing andhad enough info its just when I tried to do it i could never get it to work... This is basically what i had before:
I know im missing something but ive never done this before so i cant figure out what i am missing ![]() |
Author: | Clayton [ Fri Jun 16, 2006 4:00 pm ] |
Post subject: | |
"nums" is the variable that you are assigning the information you are getting from the file, therefore you need to declare it before you can assign it any information |
Author: | Hack.saw [ Fri Jun 16, 2006 4:08 pm ] |
Post subject: | |
OOooo... Ok now I see before i thought maybe you put it in your document to say what turing picksup or something... Now when I look back at his final code in the tut i see why he dosnt have it in the variable list *bonks self on head* he switched it for numberofmarks... haha |
Author: | Hack.saw [ Tue Jun 20, 2006 12:30 pm ] |
Post subject: | |
k lets say i made a text file or data base for an item nad recorded stuff like strength, weight, damage, etc. How would turing know which line of the text file to get that from? |
Author: | Delos [ Tue Jun 20, 2006 3:31 pm ] | ||||
Post subject: | |||||
Many ways. If you had each systematically on seperate lines, then you'd just read each line into a seperate field of a record. If they were all on one line, you'd simply parse them into the record. For instance:
This might represent First_Name, Last_Name, and Age. As you can see, they are nicely ordered, and can each easily be read into a seperate variable.
Notice that you'll have to figure out how to determine whether each line constitutes as '1st', '2nd', '3rd', or 'nth' - depending on how many fields you have. This is likely easier than parsing, but only marginally so. |
Author: | Clayton [ Tue Jun 20, 2006 3:58 pm ] |
Post subject: | |
you could also look into the seek command, which goes to a line specified by you in a file for you to take information etc ![]() |