serpent.block seems having bug[solved]

Place to get help with not working mods / modding interface.
kendoctor
Inserter
Inserter
Posts: 34
Joined: Wed Aug 05, 2020 6:43 pm
Contact:

serpent.block seems having bug[solved]

Post by kendoctor »

using serpent.block, dump this

Code: Select all

["facto.train.carriagefactory"] = {
    instanced = {
      ["31"] = {
        factoobj = {
          __self = "userdata"
        },
        order = 1,
        train = {
          carriages = {
            0
          },
          factoobj = {
            __self = "userdata"
          },
          id = 2,
          surface = {
            __self = "userdata"
          }
        }
      }
    }
  },
  ["facto.train.trainfactory"] = {
    instanced = {
      ["2"] = 0
    }
  }
using my implementation var_dump

Code: Select all

{
   facto.train.trainfactory:{
      instanced:{
         2:{
            factoobj:{
               __self:userdata(userdata)
            }(table:table)
            id:2(number)
            carriages:{
               1:{
                  factoobj:{
                     __self:userdata(userdata)
                  }(table:table)
                  train:reference(table:table)
                  order:1(number)
               }(table:table)
            }(table:table)
            surface:{
               __self:userdata(userdata)
            }(table:table)
         }(table:table)
      }(table:table)
   }(table:table)
   facto.train.carriagefactory:{
      instanced:{
         31:reference(table:table)
      }(table:table)
   }(table:table)
}(table:table)

in the same place invoking two dump

Code: Select all

function GameManager.load()
    log(var_dump(global.facto))
    log(serpent.block(global.facto))
    -- if global.facto == nil, that means game already broken
    for guid, class in pairs(persisted_classes) do
        -- if global.facto[guid] == nil, that means some features added
        -- should not change this data in on load
        assert(guid == class.guid())
        class.load(guid, global.facto[guid])
    end 

end 
Due to using serpent.block, let me confused what i'm doing wrong. It took me a long time until replacing with my implementation
Last edited by kendoctor on Mon Aug 17, 2020 11:55 am, edited 1 time in total.
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4040
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: serpent.block seems having bug

Post by boskid »

serpent.block is trying to avoid writing variables it already printed in case of cyclic or multiple references. In that case, it will print a placeholder value - here it will be "0" - but due to the nature of serpent.block, it will not print the fixing part that links all the references (it would be printed by serpent.dump). This is known serpent.block behavior. Some tiny details you may get in https://factorio.com/blog/post/fff-340.

You will notice this references when using comment=true:

Code: Select all

/c
  a = {"this is a"}
  b = {[1]=a, [2]=a, [3]=a} 
  game.print(serpent.block(b, {comment=true}))
kendoctor
Inserter
Inserter
Posts: 34
Joined: Wed Aug 05, 2020 6:43 pm
Contact:

Re: serpent.block seems having bug

Post by kendoctor »

boskid wrote: Mon Aug 17, 2020 11:46 am serpent.block is trying to avoid writing variables it already printed in case of cyclic or multiple references. In that case, it will print a placeholder value - here it will be "0" - but due to the nature of serpent.block, it will not print the fixing part that links all the references (it would be printed by serpent.dump). This is known serpent.block behavior. Some tiny details you may get in https://factorio.com/blog/post/fff-340.

You will notice this references when using comment=true:

Code: Select all

/c
  a = {"this is a"}
  b = {[1]=a, [2]=a, [3]=a} 
  game.print(serpent.block(b, {comment=true}))
I have no ideas, i dumped before, it was nil, not 0 if have already printed var. that's why i was confused.
i suggest using ref instead of zero
Post Reply

Return to “Modding help”