SenL Posted June 17, 2022 Share Posted June 17, 2022 (edited) Hi, How come the print below is "inst.prefab is forest"??? (inst.prefab should be myMod) This is in my myMod.lua: Quote inst:ListenForEvent("seasonChange", function(inst, data) if (inst.prefab ~= nil) then print ("inst.prefab is "..inst.prefab) --why does this return "forest"??? end ... end, GetWorld()) If that's correct, how do I send "myMod" inst inside this function inside ListenForEvent? Thanks. Edit: I have a feeling it's the "GetWorld()" part. What is this... is it the scope? Edit2: Changing it from Quote inst:ListenForEvent("seasonChange", function(inst, data) To Quote inst:ListenForEvent("seasonChange", function(world, data) fixed it. How? Edited June 18, 2022 by SenL Link to comment https://forums.kleientertainment.com/forums/topic/140972-how-does-listenforevent-work/ Share on other sites More sharing options...
Leonidas IV Posted June 19, 2022 Share Posted June 19, 2022 Structure of the ListenToEvent function: function EntityScript:ListenForEvent(event, fn, source) Where source is optional, if not passed, it will be the calling entity. So when the event is pushed, the function (fn) that was passed receives source and the push date. When you set a source, the first parameter of your function will be the source! There is no way for your entity to be pushed by the world! It only warns you that the season has changed! What you fixed is that you were overriding the value of inst (your item), with the world, by calling it "inst" too. Link to comment https://forums.kleientertainment.com/forums/topic/140972-how-does-listenforevent-work/#findComment-1578296 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