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 Chat / reading external text files

Author
Message
ruckertheron
1
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 6th Jun 2018 16:52
How do I read from external text files? I mean if I don't write to a file...

IronManhood
3
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 6th Jun 2018 20:21
Look at the "Read" section of commands. https://www.appgamekit.com/documentation/Reference/File.htm
fubarpk
AGK Developer
Gold Codemaster
13
Years of Service
Recently Online
Joined: 11th Jan 2005
Location: Adelaide
Posted: 7th Jun 2018 02:55
I find the easiest is to read the data with the readline command
Something like this


by defining MyArray as a type and some changes to the above code you could use it to store allsorts of other data
at the same time and have data retrieved for several players
example

JSON files are another way of achieving this
fubar
ruckertheron
1
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 7th Jun 2018 17:28
Thanks for the help.. a few minor issues here. Is this what you meant?





Assuming that this is what you meant, I still have issues.. The e$ is empty. Also note that this text file was not created in AppGameKit with WriteLine commands also...





fubarpk
AGK Developer
Gold Codemaster
13
Years of Service
Recently Online
Joined: 11th Jan 2005
Location: Adelaide
Posted: 8th Jun 2018 08:04 Edited at: 8th Jun 2018 08:23
if you get the error
Error... File does not exist!
then the filename "exam data.txt" may not be a matching name, perhaps try renaming it
Or you havent placed the text file in your projects media folder and your program cant find it

And the above will work with text files or files that have been made in or saved in text format like you would use in Notepad
Binary files or other formats extensioned .txt wont neccesarily work

fubar
fubarpk
AGK Developer
Gold Codemaster
13
Years of Service
Recently Online
Joined: 11th Jan 2005
Location: Adelaide
Posted: 8th Jun 2018 08:16 Edited at: 8th Jun 2018 08:18
in the above code I just posted will print the string at index I for example 100 lines of text will have 100 elements in the array
therefor size would be equal to 100. arrays start at index 0 so the first line would start at index 0 and then continue up until
line 100 being index 99 if that was the case in the example above
fubar
fubarpk
AGK Developer
Gold Codemaster
13
Years of Service
Recently Online
Joined: 11th Jan 2005
Location: Adelaide
Posted: 8th Jun 2018 08:41 Edited at: 8th Jun 2018 08:43
or you could load it as one string

both methods would consume allot of memory if you just wanted to print it once you could do it line by line as you read them from the file
fubar

Login to post a reply

Server time is: 2018-10-16 19:11:00
Your offset time is: 2018-10-16 19:11:00