Keeping Track of Events

I’m pretty new to events and I’m starting to feel a bit overwhelmed by just how many events we’re creating and referencing in rapid succession. Because I didn’t work out how I want the code to work myself, it’s getting difficult to keep track of the web of connections that we’ve created across multiple scripts.

So I guess I have sort of a process question.

What is your general process when you’re deciding how you’re going to structure your code, or do you have any tips in that regard? For example, are you creating flow charts listing out how you want all of these events to interact before you start coding? How do you mentally keep track of which events you’ve created across various scripts?

Any advice along these lines would be greatly appreciated, thanks!

My personal method depends on the scope of the project. After I took the RPG course, I got in the habit of doing flow charts to prevent circular dependencies or connections that were undesirable. For a small project I won’t do this. If the scope grows to a size where I am worried there will be circular dependencies, then I need a flow chart to keep track. A good tip is if you don’t know the scope, start a flow chart right away, because it’s way easier to do it as your are going along, then trying to do the whole thing in advance, or trying to do the whole thing at the end to check your work.

The big advantage of events, or any listener behaviour in general, is you don’t have to keep track of it too closely. Really you just need to know if something subscribes, it should probably unsubscribe at some point. For example, if you have a unit death event. All you need to know is that it is called when a unit dies. Then whenever another script needs to reference it, you can subscribe. You don’t need to remember where it is called or how many times it’s subscribed to, as along as you know it’s called when an unit dies.

More important is to keep your scripts organized. So if you pop into the unit script, the events are are declared very clearly at the top in their own commented section. Then when you do go looking for things, they are easy to find. This is all my own experience, so take it with a grain of salt.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms