Moai personal thread

Alpha 17: Writing to the console

There is an old topic by by Tom regarding how to write to the log:
http://discourse.stonehearth.net/t/how-to-log-from-your-mod/5222

However, I could not get this method to work. There are instances of logs in the Lua code, the formula for which I replicated exactly in my own code. However, logging also requires another component: a modification of your user_settings.json. While the method described in Tom’s topic still works to open the console, no matter how much I tried, I couldn’t actually get it to display any logs. SO: If anyone here knows how to get the logging to work right, please reply to this post!

However, as I still have coding to do, I managed to kludge together a way to write to the log regardless. I did so by looking up some of the console text that it was printing out every time the game started, and copying the method from there. Here is the function I now use:

function log(text)
  radiant.log.write('my_mod_name', 0, text)
end

Use it like so:

log("hello world")

Don’t forget to add the console setting to your user_settings.json:

...
"logging": {
  "show_console": true
},
...

Edit
Also, starting from now, I am no longer vivisecting Stonehearth. On one hand, doing so is faster, but it comes at a cost of risking your stuff being overwritten in an update. I’m still not making .smods, but at least I keep my stuff in a separate folder.