Jump to content

What are the events?


Cyde042

Recommended Posts

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. :p

Link to comment
Share on other sites

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. :razz:

 

 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

 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

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

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.

×
  • Create New...