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 / WriteString / Line Query

Author
Message
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 27th Mar 2016 18:51 Edited at: 27th Mar 2016 18:54
I have been playing with writestring and writeline commands to achieve a readable .txt file which is comprised of strings ending with carriage return/line feed when I need.

Point 1) writeline has a CR as a default, writes text which is readable but does not allow strings to be concatenated once written. Some will suggest join the string 1st and then write but that is not easily feasible on this occasion.
Point 2) using writestring allows strings to be concatenated,is normally unreadable, but by adding a carriage return and a linefeed anywhere in the written text makes it readable, e.g Writestring(1, animal$+Chr(13)+Chr(10)), however it creates a whitespace at the beginning of the next line which I am unable to remove e.g using TrimString since it is not part of the string.
Point 3) if I do the same using writestring2 then 3 whitespaces are inserted at the beginning of that written line.

I think these may be minor bugs but has anyone else been affected?

Attached a basic test.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Mar 2016 20:46 Edited at: 27th Mar 2016 20:48
If you add a CR+LF at the end, you are effectively using WriteLine.
Can you use a different data separator, for example ~
You can then parse it out using GetStringToken(). For example, this is some of my data...

SETSPEED~1000&2000~100

In this string I parse out the parameters using ~
Secondly, some parameters have sub-parameters separated by &.
So I use 2 levels of GetSringToken().
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 28th Mar 2016 14:04
Hi, thanks BatVink. The annoying difference between Writestring + CR + LF and Writeline is that Writestring + CR + LF inserts a white space at the beginning of the next line and 3 white spaces on the same line if you use Writestring2.
However I have found an easy work-a-round in using writestring until I need a CR + LF and then substitute it for a writeline. This allows me to concatenate written strings before introducing the writeline CR/LF which then takes me nicely to the next line without whitespaces being added.

Although writestring is not meant to be readable, the addition of either a writeline or a writestring+CR+LF anywhere in the written text document does make it readable and to this extent I still believe the white spaces are a minor bug.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Mar 2016 17:33
Good to know, thanks for sharing
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Apr 2016 23:06
WriteString and WriteLine are meant to be used differently. And which you use really depends on what you want to do.

And mixing them in a file is probably not a 'best practice'.

The WriteString (and WriteString2) is part of the set used to create binary files that are not human readable. The other commands are WriteByte/Float/Integer. Each is then retrieved from the file using the associated Read command (ReadString, ReadByte, ReadFloat, etc.).

If you want a human readable file, you use WriteLine and then use ReadLine to get each line of data and then do something.

If you want something that lets you save lots of different things without having to convert them to and from strings, you go with the binary formats.

I use the binary forms for the actual config file used in my WIP game. This makes it hard for a user to tweak the settings and 'cheat'. I have a level editor that lets me manage the files.
Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-25 08:31:48
Your offset time is: 2024-11-25 08:31:48