Jump to content

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

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.

 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.

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)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...