Engine error at "triggerOnShee" in r79.4

Bugs will be moved here once resolved.

Post » Thu Feb 23, 2012 10:37 am


@Geo found an error when using function plugin.

Geo's test capx has two triggered event(condition), one is "F1", the other is "F2".
In event(condition) "F1", it will trigger "F2". After running all actions in event(condition) "F1", the engine trigger "F2" again.

I guess that it might be caused in eveng.js, "triggerOnSheet" function. Check the loop index "i" at line 1581.

rexrainbow2012-02-23 12:11:23
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 24, 2012 12:39 am

This is a bug in the function object. The way triggers work is triggering "On function" with fn_name = F1 triggers both "On function F1" and "On function F2", with the intent that only "On function F1" returns true. In "On function F1", which is first in the event sheet, "Call F2" sets fn_name = F2 and again Construct 2 triggers both "On function F1" and "On function F2", and this time only "On function F2" returns true. However the value of fn_name has been overwritten, and now execution returns up the stack and Construct 2 is still triggering all "On function" events for the original "Call F1" action. Since fn_name was overwritten to F2 in the nested function call, it should trigger "On function F2" with fn_name = F1, but it's now F2 which returns true and incorrectly runs the event.

Relevant part of the plugin:

[code]     FunctionKlassProto["_CallC2Event"] = function(name)
     {
        this["fn_name"] = name; // *** overwrites a single value
         this["plugin"].runtime.trigger(cr.plugins_.Rex_Function.prototype.cnds.OnFunctionCalled, this["plugin"]);
     }; [/code]

Instead you need a stack of state like the event system uses: you need to push the function name to a stack, trigger, then pop the function name from the stack. In 'OnFunctionCalled', only compare to the name at the top of the stack.
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578

Post » Fri Feb 24, 2012 9:42 am

@Ashley

I got it. Thanks and sorry for wasting your time.rexrainbow2012-02-24 09:42:43
B
97
S
22
G
178
Posts: 4,118
Reputation: 104,043

Post » Fri Feb 24, 2012 3:13 pm

No worries :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,951
Reputation: 178,578


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests