Page 1 of 1
Issues with serialization
Posted: Wed Oct 07, 2015 10:12 am
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.
Re: Issues with serialization
Posted: Wed Oct 07, 2015 4:00 pm
by Rseding91
You can't use entities as indexes.
Re: Issues with serialization
Posted: Thu Oct 08, 2015 5:32 am
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...

Re: Issues with serialization
Posted: Thu Oct 08, 2015 8:47 am
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.
Re: Issues with serialization
Posted: Thu Oct 08, 2015 9:07 am
by ratchetfreak
For non moving entities (buildings) you can use the surface and location combined as the key instead.
Re: Issues with serialization
Posted: Thu Oct 08, 2015 2:10 pm
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...
Re: Issues with serialization
Posted: Thu Oct 08, 2015 9:50 pm
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.)
Re: Issues with serialization
Posted: Fri Oct 09, 2015 5:21 am
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.
Re: Issues with serialization
Posted: Fri Oct 09, 2015 5:44 am
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.
Re: Issues with serialization
Posted: Fri Oct 09, 2015 7:50 am
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.
Re: Issues with serialization
Posted: Sat Oct 10, 2015 3:30 pm
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
Re: Issues with serialization
Posted: Sat Oct 10, 2015 6:11 pm
by theRustyKnife
Cool, that will make things easier
