Page 1 of 1

Fixing [Z] Adventure

Posted: Tue Jul 12, 2022 5:19 pm
by hasanchik
(This is my first topic btw)

So the other day i found this cool mod (https://mods.factorio.com/mod/ZAdventure) about random generated structures, kind of like that ruins mod.
The difference here is that there is much more and the structures can be way bigger with neat features like for example a racing track. Anyway, i was really sad to find out that it's broken. As of 0.18 a single change in the factorio api broke it (https://www.reddit.com/r/factorio/comme ... ?context=3), and i tracked it down to this line: (ZAdventure_2.17.2\lib\bplib.lua line 20)

Code: Select all

return zzlib.inflate(util.decode(prepareInput(input))) 
I went ahead and changed it to this:

Code: Select all

return zzlib.inflate(game.decode_string(prepareInput(input)))
I looked at the api and apparently the zzlib.inflate is useless, but idk. Anyway if i do that i get this weird error:

Code: Select all

  22.804 Error ModManager.cpp:1558: Failed to load mod "ZAdventure": __ZAdventure__/lib/bplib.lua:20: attempt to index global 'game' (a nil value)
stack traceback:
	__ZAdventure__/lib/bplib.lua:20: in function 'ParseToJson'
	__ZAdventure__/lib/bplib.lua:16: in function 'ParseToArray'
	__ZAdventure__/lib/bplib.lua:25: in function 'CalculateAreaData'
	__ZAdventure__/data-final-fixes.lua:80: in main chunk
I have used lua alot before but not with factorio api. Can somebody help me revive this ancient mod? Thank you in advance!

Re: Fixing [Z] Adventure

Posted: Wed Jul 13, 2022 12:03 am
by Silari
That script is being run in the data stage, at which point LUAGameScript (available as 'game' in the API) does not exist yet - it only exists after a game is loaded. As that's the only place where decode_string is defined, I don't think this is possible with the current API. This wasn't an issue with the previous encode/decode since it was a separate LUA file that could be require'd wherever.

You can make a request in the modding interface requests section of the forums to get the decode/encode commands available in other stages. It's quite possible it was just overlooked that it wasn't available the same way.