Sooo this isn’t really SH related, but if you were ever curious what I’m doing when I’m not modding, allow me to put your questions to rest:
Wow. That reminds me, I should get back into Arduino sometime.
You really should. Getting an Arduino for the last New Year’s was what made me get into electronics. I’ve since been doing a bunch of home automation stuff, with a Linux on a laptop in my closet serving as the home server. I have several cameras combining their feeds to it, and I’d like another one on my balcony. What you’re seeing is a prototype of the power transmission system that will zip electricity across 3 layers of glass and approx 30 cm distance, to power said balcony camera. I live in cold places, so while just running a wire outside is possible, it is not preferred, and this is a much more fun alternative
So it turns out that you cannot find out the location of an entity (through a component on that entity) using any of the standard creation lifecycle methods (
activate, post_activate, initialize, create). You actually have to wait a little before that information is accessible. Here’s how I ended up doing it:
function MyComponent:post_activate() self._loc_timer = stonehearth.calendar:set_timer('item waits for location', '1m', function() local mob = self._entity:get_component('mob') local location = mob:get_world_grid_location() end) end
That’s because the entity can be fully created and live for any length of time without ever being placed in the world. You can try listening to the
Protip for modders: if you are working with regions or collision shapes that are created / moved dynamically in Lua, check out
stonehearth.debug_shapes:show_box function. It draws a box around your region, so you can see it right in your game and adjust it by sight, not by math and blindly feeling around.
This may be so… but running
mob:get_facing() on the entity that was just
on_added_to_world still results in a facing of 0, even when it clearly is not 0. Doing things with a 1 minute calendar solves both problems.
Yeah, that’s annoying. Fixed in the next release.
No problem at all. Glad to see it helped someone.