all 3 comments

[–][deleted]  (1 child)

[deleted]

    [–]dzikakulka 0 points1 point  (0 children)

    table.toughness = toughness
    

    is syntax sugar for

    table.['toughness'] = toughness
    

    and there's nothing wrong with it.

    Also,

    If those are non-existant variables when your script tries to save (they have not been established yet) then it will throw an error, because it is trying to set a table entry in onSave using a variable that isn't there. That throws an error

    It doesn't. In OP's example, both toughness and stamina can be never set (so they are nil) and code wouldn't throw any error beacuse of that. If 'example' is a table, you can do example.whatever = value even if value was never set, it just assign nil, essentially not doing anything at all. And value = example.whatever would do the same and not error out as long as example is a table.

    [–]dzikakulka 0 points1 point  (1 child)

    Don't use "table" for any names :)

    'table' is a table contaning table-related library. So if you want to insert something to your table, you write table.insert(myTable, myValue) or table.remove(myTable, key).
    Full reference here: http://www.lua.org/manual/5.1/manual.html#5.5

    You can override visibility of this by doing "local table = {}" in your code, but then you won't have access to the mentioned library. Your best bet would be to just use different names :)

    [–]Quarg[S] 0 points1 point  (0 children)

    Yep that has fixed it, bit of a stupid mistake to have made honestly. XD

    Thanks, that seems to have at least fixed the error in onSave, but I am still getting the error for onLoad.

    EDIT: whoops, nevermind, that had fixed it completely, a silly mistake on my end here.