[Solved]How do I use "runtime.trigger" in plugin?

Get help using Construct 2

Post » Sun Sep 18, 2011 11:58 pm

Hi, I write a simple plugin to implement 'function' object like in C1.
There is my plugin and test capx.
http://dl.dropbox.com/u/5779181/plugins.7z

I call 'runtime.trigger' in acts.CallFunction to trigger cnds.OnFunctionCalled.
[code]     acts.CallFunction = function (name)
     {
        this._function_name = name;
       this.runtime.trigger(cr.plugins_.MyFunction.prototype.cnds.OnFunctionCalled, this);
     };
     cnds.OnFunctionCalled = function (name)
     {
          return (this._function_name == name);
     };[/code]
It works fine, OnFunctionCalled can be triggered correctly.
But, there are something wrong when go back to caller.
I find that in eveng.js, function: run_actions_and_subevents
[code]          // Run each action
          for (evinfo.actindex = 0, len = this.actions.length; evinfo.actindex < len; evinfo.actindex++)
          {
              if (this.actions[evinfo.actindex].run())
                    return;
          }[/code]
evinfo.actindex is incorrected when runtime.trigger finished.

In my test case,
evinfo.actindex = 2 when executing action line 3 (Call function).
Event "On function" only has 1 line, so that evinfo.actindex = 1 when leaved.
Now, go back to previous for loop (run_actions_and_subevents). The evinfo.actindex changed to 1 (before was 2)
So that line 3 will be executed again, and again.


Do I miss something about using 'runtime.trigger'?rexrainbow2011-09-23 09:30:07
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Mon Sep 19, 2011 12:18 am

Oops, you've uncovered an engine bug - triggering from an action does not preserve the current running event. I've fixed it for the next build. If you try again when it's out, it should work.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Sep 19, 2011 5:34 am

Thanks a lot.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Tue Sep 20, 2011 3:45 am

Function plugin test pass in r57, thanks.
B
97
S
22
G
178
Posts: 4,121
Reputation: 104,049

Post » Tue Sep 20, 2011 2:44 pm

Thanks, good to know!
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, Artpunk, Magistross and 30 guests