AgainstMatter Posted January 29, 2015 Share Posted January 29, 2015 Could someone explain how events work?What events are there and how do i find them? Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/ Share on other sites More sharing options...
seronis Posted January 29, 2015 Share Posted January 29, 2015 (edited) An event is just a table that contains a label plus a set of data. The label is the event name. The 'event' is always targetted at a specific object in memory like the world, a player, a monster, or some global component like a piece of the interface or the weather manager or clock. Klei has done a good job setting it up so basically anything can accept events you push on them and those events can have ANY label you choose. There is no master list that defines if a given event name (the label) is valid or not. Anything is valid. When an event is pushed onto an object the event system forwards that event to everything that has been registered as a listener. There can be any number of listeners and every one of them will get called and the data that was passed in with the pushevent call will get passed to the event handler. So that explains how they work. How you find them is just do a file search for "PushEvent" Edited January 29, 2015 by seronis Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/#findComment-607447 Share on other sites More sharing options...
Heavenfall Posted January 29, 2015 Share Posted January 29, 2015 Woah, you made it sound totally complicated. Simplified, an event is code that sets up a certain function to run (using listenforevent) whenever an event is pushed (using pushevent). So for example you can push an event whenever the player character speaks, and you can listen for that event to run some function that reduces sanity. Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/#findComment-607485 Share on other sites More sharing options...
Mobbstar Posted January 29, 2015 Share Posted January 29, 2015 (edited) I'll try to put it even simpler: Things can use "pushevent" to fire an event. If other things listen for that event (by that thing) using "listenforevent", they will always do what they got told to do then, and only when that event fires. EDIT: To name an example:An event is like the sun saying "wakey wakey" when rising.An event listener is like blue mushrooms going "is that the sun?! hide!" That's literally how it works in the game. Edited January 29, 2015 by Mobbstar Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/#findComment-607517 Share on other sites More sharing options...
Corrosive Posted January 30, 2015 Share Posted January 30, 2015 Distilling that further: Pushing/firing an event is an announcement of something happening. Anything listening for that announcement can react, if necessary. Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/#findComment-607933 Share on other sites More sharing options...
Blueberrys Posted June 9, 2015 Share Posted June 9, 2015 (edited) And some code examples.local event_name = "unique_name"local data = { value1 = 1, value2 = "okay",}-- Push the event to the instanceinst:PushEvent(event_name, data)-- ...-- Function to receive eventlocal function event_received_fn(inst, data) -- inst = the instance which received the event -- data = data object received from the event local val1 = data.value1 local val2 = data.value2 print(val1, val2)end-- Detect pushed events and send the data to a functioninst:ListenForEvent(event_name, event_received_fn)- Shortened version:-- Push eventinst:PushEvent("unique_name", {value1 = 1, value2 = "okay"})-- ...-- Receive event and use datainst:ListenForEvent("unique_name", function(inst, data) print(data.value1, data.value2)end) Edited June 9, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/49943-events/#findComment-645567 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now