Copy real-time data to text file

Monkey Forums/Monkey Programming/Copy real-time data to text file

CHK10(Posted 2016) [#1]
Hello, I have just started using Monkey X with the Eclipse plugin and I'm programming a Garmin app that show the heart rate of a person.
This heart rate is being showing on screen on real time and I would like to save this info in a text file but I don't know how to do it.
Someone could help me with the code?
Thanks.


ImmutableOctet(SKNG)(Posted 2016) [#2]
You've got a few options depending on how much data you intend to save. Although, I'd be careful saving data too often, as it can result in poor system performance. You're probably dealing with flash storage, though, so you don't have to deal with moving parts.

At any rate, here are your options and their shortcomings:

* 'SaveState' and 'LoadState' are useful for storing variables in a string-based format. Although, 'SaveState' has limited storage on some targets. To my knowledge, these are supported on every target.

* 'FileStream' allows you to read and write whatever you want to/from the file system. File size and file mode restrictions are completely system specific, and usually aren't a problem. Along with the ability to write strings to the device's internal storage, this option also allows you to read and write binary formats.

In addition, 'FileStream' objects are standard 'Streams', so they act as a great means of abstraction, and allow you to provide order to your serialization process.

The downside to 'FileStream' is the number of supported platforms, though some targets, like HTML5, have alternatives. Although, the Android, iOS, and GLFW targets are supported.

* 'SaveString' and 'LoadString' are similar to the state commands, although the former is only available from the legacy 'os' module, and is non-portable because of this. On the bright side, 'LoadString' has its own utilities.

As far as writing files/values goes, these are your options. There one or two more for reading files, but these are probably the most relevant to your situation.

As a side note, 'brl.json' may be useful if you intend to use a more complicated string-based format.