MoMods Need-help, Force Fields edition.

Place to get help with not working mods / modding interface.
Post Reply
User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

MoMods Need-help, Force Fields edition.

Post by ludsoe »

Whats up guys, I'm starting this thread since it was decided I post here instead of communicating directly to the developers.
Currently Ive been working on Force Field posts(See GIF below.) And they work wonderfully, but have a slight issue.
After reloading with some placed posts, the game crashes. If done some personal testing, and it seems related to something that causes my entire lua table storing entities to nil out.
Gif
Download: http://www.mediafire.com/download/c67mr ... hstuff.zip
Includes the mod and a test save.
Install Mocombat to data folder.
Testing.zip to saves folder.

How to reproduce: Load the Testing save up, place some force field posts then save and reload that save. If you did it right you should get messages in console about Posts and fields not being valid, then the game would crash shortly after.

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ficolas »

I cant download it, I get a white screen, are you using the glob table to store the entities?
Edit: Ok just dowloaded it and you are not.

All variables arent saved, only the variables in the global table are saved, so you need to add every var you want to be saved to the glob table (glob.blablabla)
Last edited by ficolas on Thu Mar 20, 2014 4:19 pm, edited 1 time in total.

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by drs9999 »

I just had a quick look into your code, but I think you are right with your guess.

The problem is that you do not store all needed variables, tables whatsoever in the the "glob" table.
It does not matter if you declare global variables, they are only valid in the current "session". The only thing that is restored after loading a game is the glob-table, so you might want to store your stuff there.


btw. I do not get the point of the "SubribeOnBuilt"-function
Where is the advantage instead of using the following?

Code: Select all

if event.createdentity.name == "fooEntity" then
  doSomethingWithBuiltEntity(event.createdentity [, arbitraryParameter ,...])
end


p.s. dammit, too late :D

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ludsoe »

I do save the variables. I save all the entities in a table withen the glob table, and use the keys from the entity table to save the post and field connections. Also you guys didn't do the how to repeat. The problem isn't that the data isn't saved, the problem comes after the data is recalled. You can test this by reloading a save with placed post and damaging the force field with a weapon. (Before the tables nil out though.)
IdoSave
drs9999 wrote: btw. I do not get the point of the "SubribeOnBuilt"-function
Where is the advantage instead of using the following?

Code: Select all

if event.createdentity.name == "fooEntity" then
  doSomethingWithBuiltEntity(event.createdentity [, arbitraryParameter ,...])
end
Makes me feel better about myself.

kovarex
Factorio Staff
Factorio Staff
Posts: 8078
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by kovarex »

Just one note that might or might not be relevant. You can never save functions pointers in the save.

User avatar
darius456
Fast Inserter
Fast Inserter
Posts: 222
Joined: Thu Jan 02, 2014 6:33 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by darius456 »

Hmmmm force shield is my mod :evil: Next Monday I will upload new version... ;)

Your device is more like laser wall from C&C rather than force shield... But please continue, great job.... More mods = better.
Last edited by darius456 on Thu Mar 20, 2014 5:14 pm, edited 1 time in total.
Lenovo Y580 8GB Ram GF660m 128GB SSD W7

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by drs9999 »

So I did:
ludsoe wrote:How to reproduce: Load the Testing save up, place some force field posts then save and reload that save. If you did it right you should get messages in console about Posts and fields not being valid, then the game would crash shortly after.
And also that:
ludsoe wrote:You can test this by reloading a save with placed post and damaging the force field with a weapon. (Before the tables nil out though.)
I do not receive a message nor does the game crash for me. I guess I need further instructions :D

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ludsoe »

kovarex wrote:Just one note that might or might not be relevant. You can never save functions pointers in the save.
I don't, I had to devise another method to save functions when working with MoTimers. As I said before, its a problem with my entity pointers becoming invalid after some time. The only reason my system would nil out one of the pointers is when the entity.valid returns false, this is wrong because the entity's are still there. I can touch and damage them.

Snip From script.dat
SaveData
drs9999 wrote:I do not receive a message nor does the game crash for me. I guess I need further instructions :D

Really? Hm.... How long did you wait? It usually takes 20-30 seconds to kick in, after loading. Also did you place the posts in a line like the gif?
If so then it might be a client-side problem, Ill re-install factorio and give it another shot. Also are you using the windows version of factorio? 64 or 32 bit. Finally are you using the latest experimental build(0.9.3)?

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ficolas »

I have crashed several times for the entity var beeing nil, you are only checking if it is valid, not if it is nol, you also need to check if it is nil I guess but I see no reason for it to turn nil.

Also Im sure you arent using glob tables! At least not in the thing you provided...

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ludsoe »

ficolas wrote:I have crashed several times for the entity var beeing nil, you are only checking if it is valid, not if it is nol, you also need to check if it is nil I guess but I see no reason for it to turn nil.

Also Im sure you arent using glob tables! At least not in the thing you provided...
First of all how did you figure out what crashed your game? I just get a factorio has stopped responding and I'm dumped to desktop, secondly is there a hidden dump file somewhere I'm missing when the game crashes?
As for using glob tables, I most assure you I am. Otherwise we wouldn't be getting nil entity errors. Its just that I used some voodoo hack to modify the glob table from outside the control.lua (As changing it outside control.lua had no effect anyways.) I didn't know nil entity's crashed if you called ent.valid on them, the wiki says differently, Ill add in a nil check before the valid check and see what happens.

Honestly I just want this thing to work, as the more time I sit here trying to figure it out. That's less time I can work on other things. :|

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by drs9999 »

So I was finally able to reproduce it, too. Weird thing I am still unable to reproduce it with the savefile you post, I had to start a new game...

Anyway I doubt that it is a entity == nil error. Normally these exceptions are catched and a proper error-msg is displayed instead of a CTD. Unfortunately I do not have a better guess...

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ficolas »

I have crashed with an error message, cant reproduce the ctd bug...

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by drs9999 »

It is getting weirder :D

What does it say?

ficolas
Smart Inserter
Smart Inserter
Posts: 1068
Joined: Sun Feb 24, 2013 10:24 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ficolas »

It says that some variables that store entities are nil, thats why I said him to put the check for it beeing nil.

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ludsoe »

ficolas wrote:It says that some variables that store entities are nil, thats why I said him to put the check for it beeing nil.
OK Guys I've done some more work on trying to debunk this. Its completely outside all of our control, the game is giving me userdata objects which are placed into my entity data tables. It seems the game is doing something to the userdata tables that's upsetting EVERYTHING. I've Designed a GUI table debugger tool so you guys can check it out yourself. I also set the forcefieldthink timer to self terminate when any of the data becomes invalid, in a hope to delay the crash that happens.

You guys can see that my data tables stay perfectly intact for yourself.

Here's how:
  • Place some Force field posts so they generate a field.
  • Open the Table data browser/debugger tool using the command below.
  • Take Note of the data structures of the tables, "MLAEnts","MLALoops" (Click the buttons named after the table to open it.)
  • Close the Table browser with the command below.
  • Save your game then reload it.
  • See that the data structures are saved and reconstructed 100% correctly.
The Gui Debugger is opened and closed through the game console.
remote.call("MoDebug","OpenGui") --Opens the Gui
remote.call("MoDebug","CloseGui") --Closes the Gui

Download Here: http://www.mediafire.com/download/c67mr ... hstuff.zip
I've only included the mod folder this time.

drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by drs9999 »

kovarex wrote:Just one note that might or might not be relevant. You can never save functions pointers in the save.
That is my next guess

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: MoMods Need-help, Force Fields edition.

Post by ludsoe »

drs9999 wrote:
kovarex wrote:Just one note that might or might not be relevant. You can never save functions pointers in the save.
That is my next guess
If you checked out the GUI debugger, the "Subscribed" table isn't saved. Its rebuilt every session. Only the tables "MLALoops","MLAEnts","Timers" are saved. (Which contain no functions.) The problem is still at large, and I suspect it has something to do with the way I'm reloading the entity data. Only way to be sure is to have a developer look at whats happening to the entity data. Specifically after the game reloads.

Post Reply

Return to “Modding help”