Proposal of name parameter for official function

For developers using the Construct 2 Javascript SDK

Post » Tue Feb 18, 2014 4:25 pm

Some users (actually, it is my team member) said that it would be better to have a name parameter input (name align) for official function plugin.

I try to propose a solution for this requirement.

1. Prepare input parameter by action:set parameter which gives a string name and it's value, stores them into a {name:value} table.
2. Call function. In function plugin, put the {name:value} table into stack.
3. In trigger event, using condition: declare parameter to align name to index, and it's default value.
- The first declaration name will align to index 0
- The second declaration name will align to index 1
...
So that the function plugin will have a name to index mapping table.
And it will try to fill the passing parameter value list.
Now the plugin has a name to index mapping table, and an extended parameter value list from {name:value} table.
4. User could use name (or a number index) to get the value under cond:on function.

Source code of modified official function plugin
Capx

This changing will backward compatible for original events.

I agree that plugin maker should avoid to duplicated plguin from official one. So please consider to implement this name align feature in offical function plugin @Ashley .rexrainbow2014-02-18 16:33:31
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277

Post » Tue Feb 18, 2014 4:56 pm

I second that, If it is possible and does not have too many problems, that would be great for complexe mathematical functions, and for any functions really, more easier to understand
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Feb 18, 2014 6:14 pm

You can always name a constant global variable "N" with value 0 in your example.

Instead of having to use the "0" index with less meaning, you can instead replace it with the "N" variable (if that makes more sense to you).

Example capx
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,295
Reputation: 70,795

Post » Tue Feb 18, 2014 6:48 pm

Does this really have much of an advantage over immediately unpacking parameters to local variables as the first thing 'On function' does? Both ways you have to create a mapping of index to name, just that this way you do that with conditions instead of actions. Local variables also allow for nicer naming in expressions (n instead of F.Param("n")) and are fast, whereas named parameters will require a lookup.
Scirra Founder
B
398
S
236
G
88
Posts: 24,428
Reputation: 194,625

Post » Tue Feb 18, 2014 6:49 pm

[QUOTE=Kyatric] You can always name a constant global variable "N" with value 0 in your example.

Instead of having to use the "0" index with less meaning, you can instead replace it with the "N" variable (if that makes more sense to you).

Example capx[/QUOTE]

@Kyatric : when you call the function, you can set only

Parameter 0
Parameter 1
etc.., it is not like you can set
Parameter My_Constant_So_Awesome

I think that is what it is about too

EDIT: If that is too much, not a big deal I agree (+ninja'd).Aphrodite2014-02-18 18:50:31
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Feb 18, 2014 10:57 pm

@Ashley @Kyatric

Just like @Aphrodite said, user could not assign value by name index when calling a function. It will be difficult to pass values when the function has 20 parameters. (Well, I agree that a function with 20 input parameters is not a good coding style, but my team member still want to do that.)

The consider of making name align in conditions instead of actions is, I thought it might be more readable since the parameter declarations are more closer to condition:on function , they are at the same block.rexrainbow2014-02-18 23:04:56
B
108
S
26
G
272
Posts: 4,471
Reputation: 152,277


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 3 guests