Login / Registrieren
DE EN FR ES IT CZ
Zurück Nach oben

How to save table entries into savegame

  • #1, by PanS 7 years ago Zitieren
    Hi,

    I created a simple function to randomize a shoe counter. Everytime the player steps into a special room a sitting character has differnt shoes. Every pair of shoes is shown once. The function works fine but of course the current table entries wont be saved. Do you have an idear?

    local tShoes = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"}
    
    function randomShoes()
    
      if Conditions["cond_no_more_shoes"].ConditionValue == false then
    
        local shoeNum = math.random(1, #(tShoes))
    
        print('shoe index number '..shoeNum..' is called: '..tShoes[shoeNum])
        print('max numbers of shoes: '..#(tShoes))
        
        if #(tShoes) <= 1 then
          Conditions["cond_no_more_shoes"].ConditionValue = true
          print('the shoe seller has nothing left in stock')
        end
        
        table.remove(tShoes, shoeNum)
      end
      
    end
    
  • #2, by SimonS 7 years ago Zitieren
    2 options:
    - serialize the missing parts into a value / condition (e.g.  value | 2^9)
    - make the table global
  • #3, by PanS 7 years ago Zitieren
    Thx. Making the table global is the easiest way. Is there a disadvantage for this option?
  • #4, by SimonS 7 years ago Zitieren
    Hm.. Could be possible that it won't remove the table entries, you would need to check, also changes in the ved will be overwritten by old savegames.
  • #5, by PanS 7 years ago Zitieren
    Indeed. This option produces a strange behavior. When I start the game (from Editor) and load the savegame the table has all entries (10). But when I start the game and play aslong the table entries are less then in the savegame (7 entries) it loads the correct number. Seems the game only filled the table with the loaded one from the savegame.

    So maybe I have to clear the table completly before loading a savegame, right?
  • #6, by PanS 7 years ago Zitieren
    Thats my full script working perfectly so far.

    Thx for your help!

    --this randomize fabians shoes
    tShoes = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}
    local cNoShoes = Conditions["cond_no_more_shoes"]
    local vShoeCounter = Characters["char_fabian"].Values["count_fabians_shoes"]
    
    function randomShoes()
      if cNoShoes.ConditionValue == false then
        if #(tShoes) >= 1 then
      
          local shoeNum = math.random(1, #(tShoes))
      
          print('shoe index number '..shoeNum..' is called: '..tShoes[shoeNum])
          print('max numbers of shoes: '..#(tShoes))
          
          vShoeCounter.Int = tonumber(tShoes[shoeNum])
          
          table.remove(tShoes, shoeNum)    
        else
          cNoShoes.ConditionValue = true
          print('the shoe seller has nothing left in stock')
        end  
      end
    end
    
    --clears shoe table before load a savegame
    function clearShoeTable()
      tShoes = {}
      print('the shoe table has '..#(tShoes)..' entries')
    end
    
    --play the correct animation when showing scene
    function playShoesAnimation()
      local numShoes = vShoeCounter.Int
      if numShoes <= 42 and cNoShoes.ConditionValue == false then
        startAnimation("Scenes[room_03_lounge].Objects[set_fabian_legs].Animations[shoes_"..numShoes.."]")
        print('play animation shoes_'..numShoes)
      end
    end