Results 1 to 8 of 8

Thread: Save Button-Labels

  1. #1

    Save Button-Labels

    how can i save the Labels of my Buttons?
    I tried it with this

    "if disableSave==true then saved_data="" end
    if saved_data ~= "" then
    local loaded_data = JSON.decode(saved_data)
    ref_buttonData = loaded_data
    else
    ref_buttonData = defaultButtonData
    end"


    from another Script, but i failed
    Please help me.

  2. #2
    That script snippet you pasted doesn't really mean anything, it just assigns some variables holding who-knows-what. First thing first, are you changing button labels at runtime? Typically they're hardcoded within the script. How does that look like in your script?

  3. #3
    Yes, im changing the Labels at runtime. I used it to give/take the Player X Money.

    myCard= getObjectFromGUID(objectId)
    myCard.editButton({
    index = 1,
    label = moneyText,
    })

  4. #4
    If you're not adding/removing buttons at runtime too (which would make this harder), you could simply save the latest label under a button index in a dedicated table, like e.g.

    Code:
    myCard = getObjectFromGUID(objectId)
    myCard.editButton({
    index = 1,
    label = moneyText,
    }) 
    buttonLabels[1] = moneyText -- 1 is the edited button index here
    -- remember to save buttonLabels table in onSave or manually when its changed
    then, in onLoad, after creating all the buttons and deserializing the buttonLabels table you can apply all the changes, e.g.

    Code:
    myCard = getObjectFromGUID(objectId)
    for index, label in pairs(buttonLabels) do
        myCard.editButton({
            index = index,
            label = label
        }) 
    end

  5. #5
    But how can i save the Label table?

  6. #6
    Easiest way to save data is to serialize a table and return it in onSave, try this snippet (stolen from https://api.tabletopsimulator.com)

    Code:
    data_table = { 
        answer = 42,
        catName = 'Clawdia'
    }
    
    -- A string returned from onSave is stored with the save file
    -- This function is called by TTS itself (you doing onSave() from script would have no effect)
    function onSave()
        return JSON.encode(data_table)
    end
    
    -- The string we saved before is passed here (if exists)
    function onLoad(dataStr)
        print('Loaded (raw): ' .. tostring(dataStr))
    
        if type(dataStr) == 'string' and dataStr:len() > 0 then
            local data = JSON.decode(dataStr)
            log(data)
            print('Loaded table logged to console tab')
        end
    end
    Save the game and load it, it should roughly show you how data persistence works in TTS.

  7. #7
    Nice, i got it Thank you very much!

    Habe a amazing day

  8. #8
    Quote Originally Posted by dzikakulka View Post
    -- A string returned from onSave is stored with the save file
    -- This function is called by TTS itself (you doing onSave() from script would have no effect)
    Nice! I had a similar issue with object visibility (which is not saved by default) and I did not know about this solution so I ended up pushing the Visible/Hidden state to the object's description (which is saved automatically). This solution would have been much more elegant.

Similar Threads

  1. Replies: 5
    Last Post: 11-11-2017, 10:23 AM
  2. Make button click functions return button parameters and/or index
    By MrStump in forum Scripting Suggestions
    Replies: 0
    Last Post: 05-16-2017, 10:10 PM
  3. [ADDED] BB code in button labels or control over color
    By MrStump in forum Scripting Suggestions
    Replies: 5
    Last Post: 04-05-2017, 02:22 PM
  4. Save Button in Save/Load not working in VR
    By Klos in forum VR Support
    Replies: 0
    Last Post: 01-30-2017, 07:40 PM
  5. [SOLVED] Game crashes on save-save file not written.
    By tallcaddell in forum Technical Support
    Replies: 2
    Last Post: 11-16-2016, 03:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •