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 / Read an externally created file into AGK

Author
Message
Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 28th Feb 2012 09:49
Hi all you 'Code Guru's'

I am new to file reading etc for AppGameKit but would loke to know how to read an externally created file into AppGameKit? Can you help with the following please...

1. What format must the external file take? (CSV, TXT, ETC) what are the field separators or type identifiers.

2. Where should I locate this external file/ (I have read about My Docs/AGK etc etc.. Can I create the folder or must it already have been created by AppGameKit?)

3. I want to read in a 'record' ( group of fields) at a time and store the data into an array in AppGameKit to use as a 'look up table'.. Is there a record identifier or do I have to 'know' the number of fields for each record and handle this myself when reading the file?

I would be grateful for assistance and especially any example code that will help.

Cheers

Rudders
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 28th Feb 2012 10:59
Quote: "1. What format must the external file take? (CSV, TXT, ETC) what are the field separators or type identifiers."

You'd have to know what you are reading. For instance, I store highscore files in a .dat file, first the names and then the scores. To read a file, you'd have to know the significance of each line and then utilise that data. File extensions matter to an extent but technically, I could save my highscore data to a .txt file and read it in the exact same way I read it now.

Here's an interesting test. Create a small program which loads an image and then creates a sprite from that image. Once done, go into your media file and change the extension of that image to anything you like (remember to also change it in the IDE). Then compile and run the code. You'll find that even though the extention has changed AppGameKit can still load in the image.

Quote: "Where should I locate this external file/ (I have read about My Docs/AGK etc etc.. Can I create the folder or must it already have been created by AppGameKit?)"

For now it's probably best to store it in 'My documents' however, I think you can get away with storing it in the media file. I believe in the next update of AppGameKit there will be a few more file commands which will give more flexibility as to where they are stored.

Quote: "I want to read in a 'record' ( group of fields) at a time and store the data into an array in AppGameKit to use as a 'look up table'.. Is there a record identifier or do I have to 'know' the number of fields for each record and handle this myself when reading the file?"

If you wrote the file then you should know how to load the data back in. Since you are just starting out, it may be best to run a few tests on smaller scale projects, just to get the hang of it.

Rudders
12
Years of Service
User Offline
Joined: 20th Jan 2012
Location: Oxfordshire UK
Posted: 28th Feb 2012 13:11
Hi Hodgey,

Thanks. I have created a 100 record file with 4 fields in each record. The first field in the file holds the number of records which i use to set up the data receiving array.

I have a file reader that enables me to create the record array and then 'lookup' a specific record by entering a code and then display the fields for that record on screen... All works great..

The thing I really was getting at in my question was 'What format should the file be created in? Currently I am creating the test file in AppGameKit and therefore the format is specific and if read using NotePad, doesn't make much sense with odd characters etc. The eventual file to read will be created outside of AppGameKit and I need to know how to format the various integer, string and float data.

I guess that I could create a simple text file and change the string to a value using the Val statement but i amy have problems with float numbers? If I do create a text file, do I separate each piece of data with a 'comma' or is it a return character, etc?

Cheers

Rudders
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Feb 2012 06:20
Quote: "The thing I really was getting at in my question was 'What format should the file be created in?"

Take your pick, you could even make one up. An extension, for me at least, is a quick way to identify what that file contains. I could give my images the extension of .dll and still be able to load them though the LoadImage() command.

Quote: "If I do create a text file, do I separate each piece of data with a 'comma' or is it a return character, etc?"

You can use either, what matters is if you know how to read that data. Storing separate pieces of data on the one line would require you to work with string commands when reading and separating the data. You'd have to search for commas and then store the data in variables/arrays etc.

Ched80
13
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 19th Mar 2012 21:02
Sorry to bump this.
I have an existing program that I'm recreating in AppGameKit and it needs to read in a CSV file. However AppGameKit appears to crash when trying to open the file. Can AppGameKit open CSV files? I must add, I've not even started reading the data, the program just crashes.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 19th Mar 2012 21:32
It should at least be able to open the file, can you send it my way and I'll have a look.

Login to post a reply

Server time is: 2024-05-08 00:10:42
Your offset time is: 2024-05-08 00:10:42