Thial Posted November 11, 2016 Share Posted November 11, 2016 (edited) Hello. I've ran into somewhat annoying problem. I have my custom character who specializes in magic and the character is able to make creatures follow itself. For now I'm experimenting with just one creature but later I will expand it into having for example 3 creatures at once. The script runs as follows: I have a table of 20 creature prefab names. When I cast the spell on a creature a loop iterates through every creature in the table and checks if if target.prefab == monster_table[row] When the creature is found in the table then I make the creature as my follower and do few other things and then I insert an array into another array I have an array called FollowerTime which holds arrays and those arrays within FollowerTime hold 2 things: target:ListenForEvent("death", OnDeath) DoTaskInTime(30, ...function...) The last DoTaskInTime function is the problem here because after the time runs out everything works great and the function makes that a creature no longer follows me and the buggy part which is setting target:ListenForEvent("death", OnDeath) to nil because after the creature is no longer my follower I don't want to check for it's death anymore. Yet target:ListenForEvent("death", OnDeath) still remains even though I'm setting it to nil and after the array is being deleted the onDeath function has no creature to refer to in FollowerTime[1][2]:Cancel() which is stopping the DoTaskInTime which removes the follower after some time. Is there some way to stop ListenForEvent like FollowerTime[1][2]:Cancel() ? here are the images of the important parts of the code: OnDeath: Adding a new follower, delayed task and listener: Thank you in advance Edited November 11, 2016 by Thial Link to comment https://forums.kleientertainment.com/forums/topic/71602-follower-listenforevent-problem/ Share on other sites More sharing options...
Serpens Posted November 11, 2016 Share Posted November 11, 2016 (edited) RemoveEventCallback, use it the same way like ListenForEvent. So in your case target:RemoveEventCallback("death", OnDeath) Edited November 11, 2016 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/71602-follower-listenforevent-problem/#findComment-836324 Share on other sites More sharing options...
Thial Posted November 11, 2016 Author Share Posted November 11, 2016 Works like a charm, no more crashes :D. Thank you very much for the help ! Link to comment https://forums.kleientertainment.com/forums/topic/71602-follower-listenforevent-problem/#findComment-836337 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