Page 1 of 1

[solved] data.write_file() - serpent to disk within data.lua

Posted: Sat Sep 10, 2016 10:10 pm
by aubergine18
Is it possible to get a .write_file() that's accessible from data.lua and data-final-fixes.lua?

Sometimes I make stupid mistake in my prototypes and it takes ages to try and work out where I've gone wrong because I can't serpent objects to file.

The only write_file() I'm aware of is part of the _G.game object, which isn't available from data.lua or data-final-fixes.lua scope.

If not available, serpent would also be a useful addition to the _G that's present during data.lua and data-final-fixes.lua.

Re: data.write_file() - for serpent to disk within data.lua

Posted: Sat Sep 10, 2016 10:35 pm
by prg
serpent is already available during the data loading phase. You can use print() or log() to get at its output.

Re: data.write_file() - for serpent to disk within data.lua

Posted: Sat Sep 10, 2016 10:36 pm
by aubergine18
Do you have an example? I couldn't find the info about print() (other than game.player.print() which isn't avail in data load stage) or log() in the API docs..

Re: data.write_file() - for serpent to disk within data.lua

Posted: Sat Sep 10, 2016 10:43 pm
by prg
print() simply writes to stdout, where you can watch the output in a terminal or redirect it to a file manually.
log() produces an entry in the log file, like "0.320 Script data.lua:7: bla".

Re: data.write_file() - for serpent to disk within data.lua

Posted: Sat Sep 10, 2016 10:58 pm
by aubergine18
I'm a bit useless when it comes to command line stuff so looks like log() is the right approach for me :) Thanks for the infos!

Re: data.write_file() - for serpent to disk within data.lua

Posted: Tue Sep 20, 2016 11:48 pm
by aubergine18
Using serpent to dump data.raw to log:

Code: Select all

log( serpent.block( data.raw, {comment = false, numformat = '%1.8g' } ) )
Result: https://raw.githubusercontent.com/auber ... r/data.raw