Restrict expression/actions inside events

For developers using the Construct 2 Javascript SDK

Post » Thu Jan 07, 2016 9:18 am

I couldn't find any information about this, sorry if my google-fu is weak.

I was wondering if it's possible to restrict certain expression/actions to be called ONLY inside a certain event.

Thanks.
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

Post » Thu Jan 07, 2016 11:49 am

Why would you want to do that? This kind of thing contradicts the way the rest of the event system is set up, so I would discourage it anyway. Some official plugins have actions/expressions which can only be used in certain triggers, but if used outside of that they are just a no-op or return an empty value.
Scirra Founder
B
387
S
230
G
87
Posts: 24,245
Reputation: 192,210

Post » Fri Jan 08, 2016 12:33 am

Because I personally do no like having a function returning an unexpected result.
If a condition can be called only inside a certain trigger and it gets called outside said trigger, in a normal programming environment it should raise an exception.

Since as far as I know there is no exception handling in Construct, it would make sense to have a parameter in the condition that forces the user to place that condition only inside the specified trigger, if not it should display (in the editor) a warning or an error, sort-of like how the Local Storage displays the [Certain events can not be moved due to restrictions on the trigger].
B
30
S
9
G
6
Posts: 525
Reputation: 8,329

Post » Fri Jan 08, 2016 1:18 pm

The edit-time restrictions are very general purpose, e.g. preventing two triggers in one event. It's true the C2 event system has no model for exceptions - typically things resort to empty values or no-ops, which I think is reasonable given the goal of making the event system easy to use: instead of trying to figure out why exceptions are breaking everything, events tend to continue to work anyway. Some plugins use an "On error" trigger so the user can find out if something went wrong, I'd suggest using that model as well.
Scirra Founder
B
387
S
230
G
87
Posts: 24,245
Reputation: 192,210


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests