Read data restore?

About Monkey 2 Forums Monkey 2 Programming Help Read data restore?

This topic contains 11 replies, has 3 voices, and was last updated by  SekaiChi 3 months, 1 week ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #14314

    SekaiChi
    Participant

    I like to use expressions with variables and mix datatypes in DATA statements when storing information, and to put labels here and there to remind myself and being able to skip portions early.

    What are your favourite replacements of READ DATA RESTORE statements when you use Monkey2?

    #14319

    nerobot
    Participant

    Maybe std.memory.DataBuffer class is what you need.

    #14320

    SekaiChi
    Participant

    Okay I was thinking of using STRUC (or CLASS) as you can have FIELD’s with expressions that includes constants and hopefully also the variables I need, but I’m open to absolutely everything. How would I use DataBuffer to structure data?

    #14321

    SekaiChi
    Participant

    But I couldn’t find a primitive that can hold a huge amount of pure information such as bytes? Are Strings meant for that?

    What are strings stored as internally UTF8 16 or 32 or some other thing?
    I would like to store a file or raw numbers inside a string (perhaps) neatly.

    I’m thinking something like this

    DATA
    FIELD “NAME” : STRING
    FIELD “SESSION” : STRING
    FIELD 10 : INT
    FIELD 16*4+Z : INT ‘ expression with variables and constants
    FIELD A$ + ” seconds” : STRING
    FIELD True : Bool
    FIELD file.bin : RAW AS FILE
    FIELD “FA789AB22FF009” : RAW AS STRING
    END DATA

    #14323

    DruggedBunny
    Participant

    DataBuffer is probably better for a load of bytes, or a simple byte array in your struct/class?

    [/crayon]
    #14325

    SekaiChi
    Participant

    That’s great! 🙂 But exactly how could I check the existence and size of a file, set the size correctly of the array and finally load it in? I’m trying to understand the documentation but it’s really not as easy as I would’ve have thought.

    #14326

    DruggedBunny
    Participant

    Docs are a bit tricky (WIP!), but this is how I would go about it, guessing that functions for interacting with files are likely going to be part of std… clicking into the std tree under Ted’s Docs tab, then finding std.filesystem, then going through the function list:

    Amend f:String to the file you want to check. (Demo may or may not work as-is… never assume system paths like this, or that OS is even Windows!)

    [/crayon]
    #14327

    DruggedBunny
    Participant

    Hmm, wasn’t able to get FileStream.ReadAll to read into the array without crashing (no idea why), so suggest using DataBuffer instead! Gives you a block of unsigned bytes, much like a byte array…

    [/crayon]
    #14331

    SekaiChi
    Participant

    Thanks! Okay, it seem abit complex to just add a file into the mix but I’ll try to understand how it works.

    #14332

    nerobot
    Participant

    Let me simplify code given above.

    DataBuffer class has Load method – use it instead of FileStream etc.

    Also there is a PeekString (for this example) and many other methods to operate with bytes in buffer – read docs of them.

    My version:

    #14349

    DruggedBunny
    Participant

    Ha, nicely done.

    #14353

    SekaiChi
    Participant

    Oh I like that.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.