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

Username:   Password: 
 RegisterRegister   
 read from file question
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
commandos




PostPosted: Thu May 01, 2008 9:50 pm   Post subject: read from file question

I'm trying to make a RPG game and i want the user to be able to save the game and open it when they feel like it. So i have all the stats of the character saved on a save file. the layout of the save file is exactly like this

Level
1
Experience
25
Health
85
and so on...

When the user decides to open a saved game, I want the program to read every other line (the values) and put them as variables in the code. Any idea of how i can get the program to just read the values and take them as an array of integers?
Sponsor
Sponsor
Sponsor
sponsor
TheFerret




PostPosted: Thu May 01, 2008 10:07 pm   Post subject: RE:read from file question

Save just the numbers and just ignore the words... so it would be like:

1
25
85
and so on...
commandos




PostPosted: Thu May 01, 2008 10:18 pm   Post subject: RE:read from file question

I was thinking of doing that but then it would make it harder for me to follow the text file since I'll probably have to play around with the numbers a bit. Is there any way to get the program to read every other line?
commandos




PostPosted: Thu May 01, 2008 10:34 pm   Post subject: RE:read from file question

Nevermind i found a solution... may not bed the best but it works and thats good enough for me right now lol

code:

open : stream_in, "stats-save.dat", get
for i : 1 .. 14
    get : stream_in, stats (i)
end for
for i : 1 .. 14
    if i mod 2 = 0 then
        a := a + 1
        statsvalue (a) := strint (stats (i))
    end if
end for
Mackie




PostPosted: Thu May 01, 2008 10:59 pm   Post subject: RE:read from file question

Try this instead:

code:
for i : 1 .. 14 by 2
     % All that other stuff.
end for
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: