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.

Newcomers AppGameKit Corner / Stumped: formatting data in .txt files for readng in AGK

Author
Message
Scifictus
4
Years of Service
User Offline
Joined: 7th Feb 2015
Location:
Posted: 15th Feb 2015 12:30
I am trying to read some level data into AppGameKit and have set up the loops to read this in using the ReadInteger command...but I seem to be missing something fundamental in my understanding of txt files.

I just want to read consecutive integers in a file (e.g. 12,5,0,0,2,65 etc.). I have tried creating text files that use comma seperators, space speerators, and one file where I have only put a single integer on each line, but still I just get random numbers in AppGameKit rather than the numbers in my text file. I am using Notepad to create the text file and am editing on Windows 7.

I looked at the examples provided with AppGameKit, ran the 'reading from file' example (which creates an integer (10), float (1,23) and string ("Hello")) and looked at the created text file to try and understand how I should be formatting my data - but the created file didnt help as it didnt look like numbers (it created something like this:" ¤p?hello")according to Notepad.

What am I missing? How do you format a .txt file with multiple consecutive integers so that AppGameKit can read it succesfully? I'm bamboozled!
Lucas Tiridath
AGK Developer
10
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 15th Feb 2015 13:38
The problem is that when you read an integer, you're reading in the next four bytes in the file as a number. However what you have are strings of ascii characters. If you want to have your data files in text format for easy editing, you should read the file by line and parse in the data in code. For example, with the following data file

data.txt


you could read in the values and display them as follows



I hope that helps.

Scifictus
4
Years of Service
User Offline
Joined: 7th Feb 2015
Location:
Posted: 15th Feb 2015 17:15
Fantastic thanks!

I have created my level editor in Excel so I have made Excel pump out a line of 4-digit numbers (0001,0016, 0120 etc without any commas/seperators). Each line has 5 x 4 digit numbers I want to read so as per your suggestion I read the whole line as a string, then I use the Mid function and a stepping loop to read each 4 digit number in from that string, then use the val function to convert that into an integer that I can put in my array.

Working! Many thanks.
Ancient Lady
Valued Member
15
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th Feb 2015 20:27
The ReadString, ReadString/Integer/Float/Byte commands are the 'read' side for the WriteString/Integer/Float/Byte commands.

Those commands treat the file as a binary file, non-human readable.

The WriteLine and ReadLine commands treat the file as a human readable text file.

If you create a simple program that reads a text file and outputs a binary file, you can maintain the values you want in a file that is easily read and edited by you. And the binary version can be used in your game to make it difficult for a user to come along and change the way the game behaves by editing the config (or whatever) file.

That is what I am doing in my Tier 2 WIP.

Cheers,
Ancient Lady
Scifictus
4
Years of Service
User Offline
Joined: 7th Feb 2015
Location:
Posted: 16th Feb 2015 12:51
Awesome - thanks for the advice Ancient Lady.

Login to post a reply

Server time is: 2019-08-18 22:53:54
Your offset time is: 2019-08-18 22:53:54