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 / Reading from a file

Author
Message
oibaf2006
10
Years of Service
User Offline
Joined: 11th Jun 2014
Location:
Posted: 11th Jun 2014 07:49
Ok it's late and I must not be seeing this. I have a file

That looks like this:
Ab*** Gar****
Sam
*****
15
6
620
1720

I can read the data up to the integer. When I read the integer
and print it out I get very large integer numbers, rather than the number i read in. What am I doing wrong?

I have 3 ReadLine statements that assign to a string
then a ReadInteger

I am using


to print the value out.

What am I missing?
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 11th Jun 2014 14:57 Edited at: 11th Jun 2014 15:29
Sounds to me like you're trying to read in a string as an integer, and so you're getting the integer value of of the bytes "15\n6" instead of 15. ReadInteger reads in a binary integer, not a string. What you want to do is to read each number in as a string, and then use the Val function to convert that to an integer that you can use in your program.

Hope that helps.

EDIT:
Just noticed your join date! Welcome to the forum!

easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 12th Jun 2014 05:07
Yep, what Lucas says. If you want to store the integer in a file, either store it as a string like you did and read it like this:

Val(Readline(fHandle))

Or write the integer to the file directly from AGK


Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"
oibaf2006
10
Years of Service
User Offline
Joined: 11th Jun 2014
Location:
Posted: 12th Jun 2014 05:58
Ok thank you both for the advice. I read the example from
file:///C:/Program%20Files%20(x86)/The%20Game%20Creators/AGK/IDE/Help/examples/files/1_reading.htm

and took it too literally. I've have switch to a string and conversion
method as you have indicated...off to find other issues as I learn the language. Thanks!

Login to post a reply

Server time is: 2024-11-25 05:37:28
Your offset time is: 2024-11-25 05:37:28