Trine 3: The Artifacts of Power

Trine 3: The Artifacts of Power

Create, Modify, Submit
Modify or create entirely new maps for Trine 3: The Artifacts of Power with the Frozenbyte Editor. Submit your maps for everyone to play and enjoy!
Learn More
Lua Listener
Hi,
Is it possible to listen on events using lua scripts ? Like, listen on a character change, or character damage, or I don't know, is there any mechanism that would look like an event bus ?
If not, what would be the equivalent triggers placeable on stage ? I mean I can always bind some value of an object (position / health / whatever) to a XXXToTriggerEntity and from then do whatever I wanted to do (like fire a lua script), but until the game is launched you don't have access to character instances, as well as some other instances that are created at game launch.
Any idea ?
Thank you
LeonardA-L
< >
Showing 1-2 of 2 comments
VonRickroll 1 20 Jun, 2015 @ 3:15am 
Hmm. I guess the answer is yes since when I exit a local coop game the console says
Failed to postEvent play_gui_game_player_leave [...]
So I guess there is indeed some kind of pub sub system but I'd like to know how it works or how we can use it. Pretty please :)
Aaaand what would be really cool but maybe I'm asking to much, is a list of all existing event we could spy on.
VonRickroll 1 25 Jun, 2015 @ 12:58am 
Ok, so I did some digging, and for those interrested, there is indeed an eventQueue, that you can get from common.CommonUtils.getEventQueue(). You cant send events to it, assuming you know what to send (there are some examples of sendEvent in the lua scripts). But in the lua part there's nowhere you'll find code that reads from it or listens to it. So nope, nothing to see here.

What I did find by almost breaking my TAB key in the console, however, were some "connectSignal..." functions, that are interresting.
Take a look at gui.ui.addPlayerChangedSignalListener(). You can take the playerManager and call connectSignal-like functions to add callbacks to the events you need.

... playerControllerChangedBind = playerManager:connectSignalPlayerControllerChanged(handlePlayerChange) playerAddedBind = playerManager:connectSignalPlayerAdded(handlePlayerChange) playerTemovedBind = playerManager:connectSignalPlayerRemoved(handlePlayerChange) ...
Note that handlePlayerChange() is the callback function to execute

I checked, those functions are also available for example in the CharacterSelectionManager, and allow you to listen on something that I interpreted as "the instanciation of a character object". But note that it is not triggered at each character switch.

A lot of somethingManagers, like SceneInstanceManager, UpgradeManager,... , accessible through common.CommonUtils.get..., also have some of these premade functions that let you spy on events. So that's cool.

Now there is a connectSignal() function that I assume is a generic function that would take two arguments, the callback and the event type/name/whatever. But I might be wrong, and since we don't have the exact prototype of the function I cannot really check. I guess I'll do some more digging :healthvial:
I'll post more if I find anything

Ultimately, for now, my goal is to find a way to trigger my own script on a character change. If anyone's got an idea :)

[EDIT] : I figured out how connectSignal works, I'll directly update the wiki when I compile all this together
Last edited by VonRickroll; 26 Jun, 2015 @ 11:44pm
< >
Showing 1-2 of 2 comments
Per page: 1530 50