How to get a mod with a controller, to write into the log?

This was my old question: How can I write a mod which will print out “Hello World” on screen?. Later I have figured that I can print to the log but unfortunately it doesn’t work so I decided to edit my post instead of opening another thread.


Hi again,
so normally it is possible to write into the log from any component/controller within the game but with my current setup this won’t happen:

analyzer.lua

local log = radiant.log.create_logger('analyzer_log')

local Analyzer = class()
function Analyzer:initialize()
	log:warning('analyzer was successfully loaded!')
end

return Analyzer

manifest.json

{
  "info": {
    "name": "analyzer",
    "version": 3
  },

  "controllers": 
  {
    "analyzer" : "file(analyzer.lua)"
  },

  "default_locale": "en"
}

user_settings.json snippet

"logging" : {
	"show_console" : true,
	"mods" : {
		"analyzer" : {
			"analyzer_log" : 9
		}
	}
}

I have tried many different things but it won’t work. Do I something wrong?

Regards,
LifeArtist


Hi there,

I wanted to start to code a mod which won’t create any new items etc. but it will need and interact with the events from Lua within the game. And based on the events it should do something.

I asked a while ago some questions where I wanted to use an external program written in another language to somehow do this. But I was directed to create a mod for this kind of purpose.

But how do I actually can create a mod which will act like a scriptable object like in unity? I have watched and read tutorials about mod creation for stonehearth but they were only creating new entities which do not really helped me.

So how would I start to create a simple mod written in lua (if c++ is not available) which will print a line onto the screen?

Regards,
LifeArtist

Okay, so I guess for what I am looking for was writing to the log. I have enabled the console debug window to check if my mod writes to it but it doesn’t.

I have configured my user_settings.json as follows:

"logging" : {
    "show_console" : true,
    "mods" : {
        "analyzer" : 9
	}
}

my sample mod analyzer.lua looks like this:

local logger = radiant.log.create_logger('analyzer_log')

local Analyzer = class()
log('outside test')
function Analyzer:initialize()
	log('test')
	logger:info('analyzer was successfully loaded!')
end

return Analyzer

I also tried to use log only because I have read in a thread on the forum that someone could get an output with log instead of logger:info() but didn’t work either. __init() also has no effect.

my manifest.json file:

{
  "info": {
    "name": "analyzer",
    "version": 3
  },

  "controllers": 
  {
    "analyzer": "file(analyzer.lua)" 
  },

  "default_locale": "en"
}

Did I miss something?

You should change your user_settings to this instead:

		"analyzer" : {
			"analyzer_log" : 9
		}

The root is the mod name, analyzer.
The nested key with value 9 is the name of your logger, analyzer_log.

Thanks, but it still doesn’t work for me :frowning:. Am I correct that a controller’s initialization function will be called once Stonehearth was started or at least the __init() function which I both try every time.

Maybe move it from initialize to activate()? That method is called after initialize

I’m not sure about your log(‘outside test’)…

The logger:info(‘analyzer was successfully loaded!’) should be ok, that’s how I do it at least.

Are you checking the stonehearth.log file? There is where my logs go. (Although I use “show_console” : false, at the user_settings)

Very strange … Still no output. I have disabled show_console and also renamed initialize() to activate(). Yeah, and the output does not show any info about my mod. Maybe it’s my setup?

inside my mod folder I have placed a folder:

+ analyzer
|-- locales (my en.json is empty except of {})
|-- manifest.json
|-- analyzer.lua

I did not changed other things for the mod.

Okay I think my lua file does not get properly loaded or even called because when I am writing bullshit into the file like:

local log = radiant.log.create_logger ('analyzer_log')

jnasudhwrk3r3

local Analyzer = class()
function Analyzer:__init()
[...]

I don’t even get a lua syntax error while editing a file which gets 100% loaded throws an error.

I’m not sure how the controllers are called.
I would guess just declaring it at the manifest would be enough.

Yeah, I have really no clue what else I can try… :frowning:

… okay deleting the en.json inside locales fixed it …