Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / loop for readline

Author
Message
Deion
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United States
Posted: 14th Sep 2011 19:34
i want to do a loop that will do a readline until it returns no value, away from my pc that has it on it so was wondering if this would work


string$ = ""


repeat

string$ = ReadLine(.....)

until string$ = ""

is this way doable??

or is there something that is or even better?

trying to read lines until the line returns no string

Cheers,
Deion G.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th Sep 2011 19:55
Read the help for file commands....

integer FileEOF( iFileID )

Deion
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United States
Posted: 14th Sep 2011 20:10 Edited at: 14th Sep 2011 20:11
saw that thanks,

but i was toying with the idea of having one file split up by one extra return so it would read til it returned no text value, then the next level it would dismiss all until it got to the no text value then continue until it got the next,, etc etcc.. kina liek a cheap xml for the time being.


example

levels.txt

would contain

Collect 6 Rocks
Collect 10 loads of dry grass
Collect 10 Loads of wood
Light Fire

Collect 100 Rocks
Shape Shovels

Collect 60 Loads of Rocks
Collect 20 Loads of Mud
Collect 15 Loads of Wood
Build Well



so if on the first level i would read the requirements

Collect 6 Rocks
Collect 10 loads of dry grass
Collect 10 Loads of wood
Light Fire

and stop,

then for level two would read the requirements

Collect 100 Rocks
Shape Shovels

etc etc etc..

Cheers,
Deion G.
Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 14th Sep 2011 20:16
You might be better off formatting your file like an old school ini file:
[level1]
Collect 6 Rocks
..blah blah..
[level2]
Collect 100 Rocks
..blah blah..

You read the file a line at a line at a time until you reach the [levelx] section you want. Import all of that data and keep reading the file until you reach the next [levelx] section.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 14th Sep 2011 20:45
Your approach seems doable. Since you may have more than one empty line, you should probably put a marker at the end of the file, like say, "END". Then when your input string = "END" you can close the file.

But integer FileEOF( iFileID ) works just as well.

And Bursar's approach would work, and so would XML formatted files, as long as you write your own XML reading code.

You could just try all the available methods, see which one you like best, really.

Bursar
15
Years of Service
User Offline
Joined: 17th Sep 2008
Location:
Posted: 14th Sep 2011 22:14
Quote: "so would XML formatted files, as long as you write your own XML reading code."

That's the reason I didn't suggest it. It would be a lot more powerful, but a load more work to get working correctly.
Deion
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United States
Posted: 15th Sep 2011 21:04
does FileEOF work in tier 2... im using

nFileComplete is initialized to 0 its a global variable initialized on program startup.

the code looks like

agk:penToRead(1, "currentMission.txt");

while (1 != nFileComplete) {
char* c = agk::ReadLine(1);
nFileComplete == agk::FileEOF(1);
}

however agk::FileEOF(1); continues to return a 0 every time. no matter if the readline returns a value or when theres no more to read and doesnt return value

Cheers,
Deion G.
Deion
21
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United States
Posted: 15th Sep 2011 21:07
ha never thought to read the documentation on readline

you use this command in tier 2 you must delete the returned string when you are finsihed with it.


so delete the char *c value?

Cheers,
Deion G.

Login to post a reply

Server time is: 2024-04-23 18:28:25
Your offset time is: 2024-04-23 18:28:25