Results 1 to 2 of 2

Thread: Help with SAVE and ONLOAD and DESTROY

  1. #1

    Help with SAVE and ONLOAD and DESTROY

    Hi there...

    I'm having a small problem working out how save/onload/destory works...

    I have a situation where a card is delt and it has a button on it. You click the button it dose something and then destroys the button. Now I have made code so if you save the game now.. next time you load the game the button is still gone...

    function onSave()
        local data_to_save = {md=midgame}
        saved_data = JSON.encode(data_to_save)
        --saved_data = "" --Remove -- at start & save to clear save data
        return saved_data
    function onload(saved_data)
        if saved_data ~= "" then
            local loaded_data = JSON.decode(saved_data)
            midgame =
            midgame = false
        if midgame == false then makeButtons() end
    So this code dose that.. there is a variable called "midgame" that if it is false it creates the buttons.. the button when pressed sets that value to true while doing its other things... then when you save it saves the state of midgame variable.. so on load it stays as true.

    The Problem

    What I would like to do is add a way to reset everything if the card goes into a deck or into a bag. Dropping a card into a deck will trigger onDestroy() but not onObjectDestroy(). So I can get code to execute as it drops into the deck with onDestroy().

    Can anyone tell me how to clear save data or reset variables as an object gets destroyed?

    I'm trying to have a button on a card, that once pressed disappears, then if you save a game while it is out on the table, on load the button is still gone.. but if you shuffle the card back into the deck to redraw, then the button is back.

    example :
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

  2. #2
    After waking up in the morning I had an idea.. what if the variable was not on the card itself?

    • I have a control object that stores the "isitspawned" variable
    • The card code check the variable on that object to determine if it loads the button.
    • When the button is pressed it sets the variable on the other object
    • When it is destroyed it sets the variable on the other object
    • The variable is saved to the jason from that object not the card

    So I have a control object with this code... (along with the save load code to store the states of "spawnButton" in the jason on save.
    spawnButton  = true
    function cardButtonSpawn(v)
        if v[1] == 'true' then spawnButton = true end
        if v[1] == 'false' then spawnButton = false end
        return spawnButton
    In the card code I have this...

        pb = getObjectFromGUID('a1dcdf') -- control object
        if pb.getVar('spawnButton') then makeButtons() end
    and in the buttons code...
    Code:'cardButtonSpawn', {'false'}) -- put at the end of the button action code
    and in the destroy code...
    Code:'cardButtonSpawn', {'true'}) -- put inside onDestroy()
    EXAMPLE : -
    My Boardgame uTube chan - Tragic's Table Top
    BGG Guild of BoardGame uTubers - Tube Tables

Similar Threads

  1. Pasting an object triggers onLoad()
    By Unreal_Ed in forum Scripting Bug Reports
    Replies: 2
    Last Post: 06-24-2017, 04:33 PM
  2. Destroy objects in a zone Error
    By AndyZ in forum Scripting
    Replies: 1
    Last Post: 02-12-2017, 07:23 PM
  3. "onload" and "onLoad"
    By Maris in forum Scripting
    Replies: 1
    Last Post: 01-20-2017, 03:58 PM
  4. [SOLVED] Game crashes on save-save file not written.
    By tallcaddell in forum Technical Support
    Replies: 2
    Last Post: 11-16-2016, 04:56 PM
  5. Replies: 0
    Last Post: 06-20-2016, 10:36 PM

Posting Permissions

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