Activities VS To statements... What is the difference?

I began using activities for my subroutines but quickly I changed them all for the easier to write, use and read To statements (To decide etc…)

What can activities do that To statements can’t do?

Activities are much more powerful: you can write before/after rules for them, check whether they are going on, add while clauses to them.

That said, you don’t need this power very often. As you have found, “To”-phrases are mostly sufficient.

It usually comes down to how complicated an action you want to perform. If it’s a simple matter of making one change or calculation each time, and it’s always the same, a “to…” phrase makes sense. But if it depends on the circumstances, and has many repercussions in the game world, an activity is much more flexible.

There are two things that “To” phrases don’t handle well:

Being detected and extended: You can always test “if the foo activity is going on,” but there’s no way to know if the thing you’re doing now was invoked by a particular phrase. Activities also have “before” and “after” rulebooks so you can add on extra behaviors to them. I had some big headaches with the low-level “update backdrop positions” phrase. I wanted to do some extra things every time it ran, but I had no way to do that.

Being replaced and varied: There is only one “to” phrase for each syntax. But you can have as many “for” rules for an activity as you want. As long as you make sure they’re ordered correctly, you can arrange for any level of nuance in circumstances.

In general, I use more “to” phrases in my game source, and more activities in extensions that I write. It’s critical to be flexible when you’re writing code that others will share, but if you can go back and modify the code easily, it makes more sense to start with something simple.

I like your approach though. I was afraid to use activities for a long time and I ended up with some awkward and bloated phrases. It’s much easier to simplify an activity to a phrase than to go the other way around…

1 Like

Thank you very much for the explanation. I guess this will be very useful since I begin to feel the limitations of the To statements, and awkard phrases are beginning to hold up the source (^^)