[PLUGIN] rex_Function2

Post your completed addons to share with the community

Post » Thu Jul 21, 2016 4:28 am

@rexrainbow
I understand now, thanks. So.. In my example, comparing to the official plugin, there's extra 2 lines of code when calling the function and 2 extra lines of code when defining the function, but that's ok
Thank you for clearing that out.
P.S. "declare parameter" and "Set parameter" should be done behind the scene, since I will declare a parameter ONLY if will use it in the function defininition
I mean, if I use a string instead of number for the parameter index it should be acting like the example you provided, without me adding extra lines of code.
Something similar to "function overload"
B
70
S
17
G
21
Posts: 478
Reputation: 16,917

Post » Thu Jul 21, 2016 4:48 am

@Cipriux

"declare parameter" has 3 effects
1. It maps the string index to index index. The first defined parameter will map to index 0.
In your case, you also could call function by index parameter (touch.X, touch.Y). Thus this rex_function2 plugin is compatible with official function plugin.

2. It could give a default value if this parameter was not assigned. You could define a lot of input parameters but only pass some of them.

3. Moreover, it could check the type of parameter value.
B
100
S
23
G
197
Posts: 4,216
Reputation: 113,922

Post » Wed Dec 21, 2016 7:48 am

hi rex,
first let me say your plugins are amazing and i use them a lot.

i have 2 suggestion for Function2M.

1) timer plugin like support

how it looks now:
start Timer "A" 1 sec
on Timer "A"
call func:"A"


the problem:
the code is very messy,
i do not want to use system wait -> you cannot stop it, and it saves the entire object filter in memory.

how to fix:
add new actions:
call function with a timer (once or looped) (with / no params)
stop timer


---------------
2) delegate support

how it looks now:

layoutstart:
call func: "A" (delB)
call func: "A" (delC)

on func "A" :
globalDel <- A.param(0)
call func: "LongProcess"

on func "LongProcess":
call func: globalDel


the problem:
the code is very messy, and it will not work if you call 2 delegates at the same time.

how to fix:
the function should keep in memory the delegates as special params even after its activation has finished.
at anytime you can call -> active all delgates(A) , A is the function name.

*i think the these 2 problems (timer & delegate) should be solved in the plugin level and not the c2 level.
still the plugin is a great improvement of orginal function, and its great for wanting something closer to "real programming"
B
21
S
7
G
3
Posts: 17
Reputation: 2,898

Post » Wed Dec 21, 2016 10:03 am

@sagispin

Thanks for using my plugins.

1) Timer is another kind of object. I would like NOT integrate timer behavior into function object.
There are some timer behaviors
- official timer behavior
- my rex_timer behavior,
- or timer in my rex_timeline plugin, which uses official function object for time-out callbacks.

You might add "system action: wait signal" to pause current actions, in one-shot timer case.


2) I am not sure what's purpose in your example.
Code: Select all
call "A" ("delB")

Here pass function name "delB" into function "A", and
Do you want to call a function which passed from input parameter?
Then you could add this function name into parameter like function "A" does.
Code: Select all
call "LongProcess"( Function.param(0) )

on func "LongProcess":
call Function.param(0)
B
100
S
23
G
197
Posts: 4,216
Reputation: 113,922

Post » Wed Dec 21, 2016 10:18 am

thanks for the quick response,

the idea was that function A is responsible for a complex task, B and C act like listeners.
they want to know when the whole process is finished.
the process A can mange its listeners by using local variables, and once he finished the task he can active those functions.
both my suggestion are very possible to do with construct 2 as it is now,
i just wanted a smoother way to use them to make the code simpler.

and i will check out those plugins
B
21
S
7
G
3
Posts: 17
Reputation: 2,898

Post » Wed Dec 21, 2016 10:32 am

@sagispin

Task or process is another kind of object. I prefer not to integrate task/process into function object, either.
It is better to have another object/plugin to manipulate task/process, to start or cancel it.
One possible solution is using my FSM plugin ( or FSM behavior).

1. Create task -- create a FSM instance
2. Initial task -- set callback function by function name in private variable of this FSM instance
3. Run task -- change state with input and private variables
4. Stop task -- change state to END, run callback
5. Delete task -- destroy this FSM instance


Edit: Here is another way to pass function call by using this plugin, which serialize function call into a string.
B
100
S
23
G
197
Posts: 4,216
Reputation: 113,922

Previous

Return to Completed Addons

Who is online

Users browsing this forum: No registered users and 0 guests