How do you handle common events?

I mainly use them for events I need to call upon often or are difficult to handle with standard events, or for making more advanced battle skills.

One common example would an item that allows you to teleport out of dungeons.  Based on a few variables being set when you enter a dungeon, the comment event checks where you are then teleports you back to the entrance.

Another would be more advanced battle skills.  By giving enemies certain skills that do nothing but call on a common event, I can give the enemy a better AI and allow animations to play when they hit your party.
Common events run by skills and items are exceptions anyway, I would say. Because there is (except for scripts) no other way of doing certain things like increasing a variable. (That Nova thing is a nice idea, by the way. 🙂 )

@Celianna: But doesn't it kind of contradict the KISS approach if you make short common events for everything (maybe even just for one SE or for changing a switch), because it becomes increasingly hard to maintain the overview that way?
@Celianna: But doesn't it kind of contradict the KISS approach if you make short common events for everything (maybe even just for one SE or for changing a switch), because it becomes increasingly hard to maintain the overview that way?
I think you have it backwards; one-liners are simple and to the point, it doesn't contradict KISS, it is a perfect example of it.


I've never had a problem with keeping my common events organized, but it's not like I have a bunch of one-liners either.
I just wanted to point out that if I use the DRY approach when there's at least 2 occassions of the same thing in the game, I get a redundant CE once I remove one of the occassions.
What happens during the game is independent of how you design it.


If I'm going to repeat it, I'm going to common event it. Saves you from ever having to worry about forgetting to change another event.

But doesn't it kind of contradict the KISS approach if you make short common events for everything (maybe even just for one SE or for changing a switch), because it becomes increasingly hard to maintain the overview that way?
Just name your common events clearly.


Having 100 events all doing "switch 3: dungeon switch ON" is not that much different from them saying "call common event: turn dungeon switch ON"


There are cases where you just know that SE isn't going to change, or that switch/variable isn't going to change, where you don't need to bother with CE's.
I don't have a concrete example, but an abstract one.

Let's say we have 3 lines of code. Line 1 and 2 are used by other events, and line 2 and 3 are also used by other events. Do we need 3 common events with each one containing 1 line of code?

If you're about to say: "No, no CE for just 1 line!", then how about we have 20 lines, with lines 1-15 being used elsewhere and 5-20 being used on different occassions. Do we need to split it into 1-5, 5-15 and 15-20?

Again, I'm just pointing out that you run into some problems (where there might not even be a definite solution to). And that in addition to deleting instances later on (making the usage of a CE redundant) or splitting everything up until you can't work with it properly anymore. It's just very vague often times, and you need to decide on each occasion what to do. I understand that, of course. 😉 But how do YOU deal with these inconsistencies and this vagueness?
There is nothing inherently wrong with having common events containing one event command. In general the amount of lines is a bad metric that can easily lead you astray and lose focus of what’s important. For your 3 line example. Well… it can be 0, 1, 2, 3, 4, 5 or whatever number of common events that is preferable. In general I cannot know.

Instead try to think of the event code in logical units. Are there parts that more naturally fits cohere. Groups of cohesive units that are sorta distinct from each other are in my experience good candidates for extractions.

There are also elements of how you want to express the functionality. This can help guide you towards a design which by itself tell a lot of what you want with the code. What your intension is.Of course sometimes it is just more convenient to create that common event or merge those two.

Should a common event become redundant, why then I would remove it. I have done so many times and I consider it a natural part of cleanup.

So to summarize this incomplete list:

  • Proper cohesion
  • Right abstraction levels
  • Convenience
Try not to over focus on the common events. There are more aspect when constructing events.

Archeia has been nice to give us a concrete example where the Nova skill will trigger 3 times every 4 turns.

My first advice to her would be to change the structure of the events to a more flat version and loosing up the conditional branches:

Nova.png


Changing the conditionals from == to >= does not change the amount of force actions when both variables are 0 and 0 initially. If for some reason the Nova counter starts as say 5, well… What happens in the == case and what happens in the >= case? Similarly, what happens if the Turn counter is say 5 or 7 when the Nova counter is 0?

Most of the time building robustness into your events isn’t too difficult although it does require you to be aware and think about it.

Another thing I am sure you have noticed by now. The nova execution code is a candidate for a common event. The biggest indicator is that the nova skill is inherent to the actor, not it does not appear to be specific to the given battle. As such I will recommend creating a common event with logic and call that from the battle event.

Nova2.png


Nova3.png


If the skill is specific to the given battle then that dependency is better expressed by keeping the logic in the battle event. There is a convenience aspect so you may still decide to extract the logic to a common event. Of course, the special circumstances should then be document.

Nova4.png


Note that the robustness changes are far more important in this case than discussions evolving around where to place the various logic.

*hugs*

Original thread: https://forums.rpgmakerweb.com/threads/how-do-you-handle-common-events.15425/