Cyde042 Posted October 6, 2014 Share Posted October 6, 2014 I can't seem to understand what determines an 'event'. What should I look at? Link to comment Share on other sites More sharing options...
przemolsz Posted October 6, 2014 Share Posted October 6, 2014 I don't know, if Don't Starve's event system is explained anywhere, but I quite understand how it works. So, first you need to start listening for an event by calling ListenForEventMethod. It constantly checks if any event was pushed.inst:ListenForEvent("some_event", function(inst) print("Hello!") end, inst)Than, whenever an event is pushed:inst:PushEvent("some_event")the function is going to activate, and you'll see something like this in console:some_file.lua(40, 1) Hello!You can have multiple listeners, and store data in events:inst:ListenForEvent("some_event", function(inst, data) print("Hello!") end, inst)inst:ListenForEvent("some_event", function(inst, data) print("It's "..data.name.."!") end, inst)inst:PushEvent("some_event", {name = inst.prefab})like that.If you write it in prefab called "duck", console will say:duck.lua(40, 1) Hello!duck.lua(41, 1) It's duck!I hope it makes any sense. Link to comment Share on other sites More sharing options...
Cyde042 Posted October 7, 2014 Author Share Posted October 7, 2014 I don't know, if Don't Starve's event system is explained anywhere, but I quite understand how it works. So, first you need to start listening for an event by calling ListenForEventMethod. It constantly checks if any event was pushed.inst:ListenForEvent("some_event", function(inst) print("Hello!") end, inst)Than, whenever an event is pushed:inst:PushEvent("some_event")the function is going to activate, and you'll see something like this in console:some_file.lua(40, 1) Hello!You can have multiple listeners, and store data in events:inst:ListenForEvent("some_event", function(inst, data) print("Hello!") end, inst)inst:ListenForEvent("some_event", function(inst, data) print("It's "..data.name.."!") end, inst)inst:PushEvent("some_event", {name = inst.prefab})like that.If you write it in prefab called "duck", console will say:duck.lua(40, 1) Hello!duck.lua(41, 1) It's duck!I hope it makes any sense. I did understand the functions, but what I wanted is the names of the event. For example, you can listen for the event 'killed' of any mob. So, where is the 'killed' event determined, how is it made to be an event? It doesn't seem to be prefab specific since I couldn't find it in a stategraph or brain. Link to comment Share on other sites More sharing options...
_Q_ Posted October 7, 2014 Share Posted October 7, 2014 I did understand the functions, but what I wanted is the names of the event. For example, you can listen for the event 'killed' of any mob. So, where is the 'killed' event determined, how is it made to be an event? It doesn't seem to be prefab specific since I couldn't find it in a stategraph or brain.Just look in specific components, killed even is in combat component. Link to comment Share on other sites More sharing options...
Mobbstar Posted October 7, 2014 Share Posted October 7, 2014 The events aren't listed anywhere, you can find them in whatever pushes them. For example, the health component causes the "health_delta" event, whenever the thing changes its current health. From what I've found, you have to make inst in inst:ListenForEvent be the same as the one in inst:PushEvent, or put the GUID (sorry for the technicallity, simple&friendly isn't my strenght) after the event name, as in inst:ListenForEvent(event, source) Link to comment Share on other sites More sharing options...
Heavenfall Posted October 7, 2014 Share Posted October 7, 2014 If you want to know all the events just search the script folder for PushEvent( Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.