LUA SCRIPT --- "IO" functions NOT shown in Simmetri / Or Reference

Comments

6 comments

  • Official comment
    Avatar
    Support

    Hi Maurice,

    Some of the built in Lua functions have intentionally been disabled for security reasons (so a malicious script can't wreak havok on a user's system). It's a tricky balance between opening up everything allowing for the most possible types of experiences to be made vs limiting things to build a trustworthy eco-system for sharing/coop.

    The good news is that there are built in Simmetri functions for saving and loading user data. Here's how:

    -- Write user data
    getHub():writeLocalData("Section", "Key", "Value")

    --Read user data
    value = getHub():readLocalData("Section", "Key", "Default Value")

    Here are links to the documentation for both functions:

    http://docs.simmetri.com/?search=writeLocalData
    http://docs.simmetri.com/?search=readLocalData

    Comment actions Permalink
  • Avatar
    Maurice Dalaimo

    Would you mind a very basic example in script form, ive been banging my head against the wall after i thought i got it working but im not getting anything OUT of the readlocal data, heres what i did. 

    -----------------------------------------------------------------------

    --test DATASTORE loading and saving

    --define HUB (root access of the scene* ) *i believe

    myhub = getHub()

    newvar = "newVariable test string..."

    myhub:writeLocalData(tostring("new1"), tostring("New2"), newvar )

    print "Made it...Saved data test"

    -- variables to load into loadstrA B loadstrA = ""

    loadstrB = ""

    failedvar = ""

    myhub:readLocalData(loadstrA,loadstrB, newvar)

    print "loaded maybe..."

    print (failedvar)

    print (loadstrA)

    print (loadstrB)

     

    -----------------------------------------------------------------------------------------------------

    im sure im doing something wrong, any help is much appreciated!

    Also do u have to SET the URL and if so PLEASE tell me this can be a LOCAL Resource (no internet required) because i will NOT have internet in many cases and asking people to be ONLINE to load or save a game / level / resource for the game / etc... would be ridiculous

     

    Thanks,

    Maurice Dalaimo III

     

    0
    Comment actions Permalink
  • Avatar
    Maurice Dalaimo

    *oops

    ---------------------------------------------------------------------------

    -- variables to load into loadstrA B

    loadstrA = ""

    loadstrB = ""

    0
    Comment actions Permalink
  • Avatar
    Support

    Sure thing, first let's see how to write out some data:


    getHub():writeLocalData("MySection", "MyStringKey", "SomeValue")
    getHub():writeLocalData("MySection", "MyNumberKey", 463.34)
    getHub():writeLocalData("OtherSection", "MyBoolKey", true)

    In the above example, we write out 3 values. The first two parameters of the writeLocalData function are always strings and identify the data's unique ID. The last parameter is the value itself that you want to write which can be a string, number, boolean, vector2/3/4, matrix etc.

    After calling a writeLocalData function, a file is written on the filesystem with the following contents (for the above example):

    [MySection]
    MyStringKey="SomeValue"
    MyNumberKey=463.34

    [OtherSection]
    MyBoolKey=true


    To read values stored, we can use the read function:

    myStringKey = getHub():readLocalData("MySection", "MyStringKey", "DefaultValue")
    myNumberKey = getHub():readLocalData("MySection", "MyNumberKey", 0)
    myBoolKey = getHub():readLocalData("OtherSection", "MyBoolKey", false)

    -- View the values
    print(tostring(myStringKey))
    print(tostring(myNumberKey))
    print(tostring(myBoolKey))

    Again the first two parameters identify the unique ID of the data which must match the write functions. If the file was written previously by a write function, then the variables on the left side of the = signs will contain the value written, else they will contain a default value defined as the last parameter of the readLocalData function.

    The data is all stored locally so it will work offline just fine.

     

    0
    Comment actions Permalink
  • Avatar
    Maurice Dalaimo

    AWESOME!!! Thank you, im still getting used to LUA , my VB.Net has me thinking of pre declarations and things that are unnecessary.

     

    Thanks again,
    Maurice Dalaimo III

    0
    Comment actions Permalink
  • Avatar
    Support

    Glad to help!

    0
    Comment actions Permalink

Please sign in to leave a comment.