Issues with serialization

Place to get help with not working mods / modding interface.
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 260
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Issues with serialization

Post by theRustyKnife »

So, I encountered this problem when I use entities as indexes in a global table and then save the game and load it again it spitts out this error:

Code: Select all

Error while running deserialisation: [string "do local _={fhed={sd60=400},fluid_powered={},..."]:1: unexpected symbol near '['
I tried everything I could but couldn't figure out what the issue was. I also tried inspecting the save file but it didn't tell me much either... I uploaded it as an attachment in case it helps find the solution.
Actually I noticed one thing: the table fluid_powered (which is the table indexed by entities) has just one index with an actual value in it, the rest is just "". I suppose that this might be the issue, but have no idea why it is or how to fix it.
Thanks to anyone who has an idea.
Attachments
test.zip
(814.17 KiB) Downloaded 134 times
Rseding91
Factorio Staff
Factorio Staff
Posts: 15882
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Issues with serialization

Post by Rseding91 »

You can't use entities as indexes.
If you want to get ahold of me I'm almost always on Discord.
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 260
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: Issues with serialization

Post by theRustyKnife »

Rseding91 wrote:You can't use entities as indexes.
Well... That might be the issue :? . The thing is though that I did this several times previously and it worked fine... And since it would be quite useful in my case I hoped I could get it to work. Also the issue only occurs when loading a save, otherwise it works too. But oh well, I guess I'll just redo the whole thing... :|
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Issues with serialization

Post by Adil »

The thing is though that I did this several times previously and it worked fine
It did? In my brief attempts to do that I couldn't get the table entries. And if you use print(entity) in different event handlers, I'm pretty sure they'll output different addressees even if the events happen to same entity.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Issues with serialization

Post by ratchetfreak »

For non moving entities (buildings) you can use the surface and location combined as the key instead.
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 260
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: Issues with serialization

Post by theRustyKnife »

Adil wrote:
The thing is though that I did this several times previously and it worked fine
It did? In my brief attempts to do that I couldn't get the table entries. And if you use print(entity) in different event handlers, I'm pretty sure they'll output different addressees even if the events happen to same entity.
Yeah that's actually true but I've been working around it by searching for the entity in the table indexes and if it was equal to the desired entity then returning it. I'm sure that's not very efficient so it's a good idea to redo it anyway...
ratchetfreak wrote:For non moving entities (buildings) you can use the surface and location combined as the key instead.
I'm working mostly with locomotives so that's not going to work. I'm not quite sure how well does saving entities in a table (not as indexes) work, but if it does, I could use that quite easily. Looks like I'll have to experiment a bit...
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Issues with serialization

Post by Adil »

theRustyKnife wrote: I'm working mostly with locomotives.
Locomotives have backername field, you can use that as index. (I do in my mod.)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
Rseding91
Factorio Staff
Factorio Staff
Posts: 15882
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Issues with serialization

Post by Rseding91 »

Adil wrote:
theRustyKnife wrote: I'm working mostly with locomotives.
Locomotives have backername field, you can use that as index. (I do in my mod.)
backername is not unique per locomotive. You could have 5000 locomotives with the same (or none) backer name.
If you want to get ahold of me I'm almost always on Discord.
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 260
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: Issues with serialization

Post by theRustyKnife »

Rseding91 wrote:
Adil wrote:
theRustyKnife wrote: I'm working mostly with locomotives.
Locomotives have backername field, you can use that as index. (I do in my mod.)
backername is not unique per locomotive. You could have 5000 locomotives with the same (or none) backer name.
Entities really should have some uniqe identifier... Something like players do.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Issues with serialization

Post by Adil »

Rseding91 wrote:
Adil wrote:
theRustyKnife wrote: I'm working mostly with locomotives.
Locomotives have backername field, you can use that as index. (I do in my mod.)
backername is not unique per locomotive. You could have 5000 locomotives with the same (or none) backer name.
Yes I know, currently I append ones to the name till it gets unique.
If more than one person uses those, we;d probably better make a small mod, that actually handles the renaming and guarantees unique names.
theRustyKnife wrote: Entities really should have some uniqe identifier... Something like players do.
Yeah, my request for backer-name like labels on entities is still floating somewhere out there. (Uniqueness could be handled by mod.) And the entity id might be cool too.
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm
Contact:

Re: Issues with serialization

Post by Adil »

Adil wrote: If more than one person uses those, we;d probably better make a small mod, that actually handles the renaming and guarantees unique names.
I've actually did that: https://forums.factorio.com/forum/vie ... 25#p112225
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
User avatar
theRustyKnife
Filter Inserter
Filter Inserter
Posts: 260
Joined: Thu Feb 26, 2015 9:26 pm
Contact:

Re: Issues with serialization

Post by theRustyKnife »

Adil wrote:
Adil wrote: If more than one person uses those, we;d probably better make a small mod, that actually handles the renaming and guarantees unique names.
I've actually did that: https://forums.factorio.com/forum/vie ... 25#p112225
Cool, that will make things easier :)
Post Reply

Return to “Modding help”