How do plugins return data?

For developers using the Construct 2 Javascript SDK

Post » Tue Jul 23, 2013 1:22 pm

I have looked at the plugin template, and under Parameter Types it lists things like:

Number
String
CmpParam
etc.

These are for input (passed to the plugin).

How are values passed back from the plugin call to the game? Either an action, like "connect()" or an event, such as "onError()"). I think events are called conditions in the SDK.

If its possible pass data back, can a two dimensional array of numbers be passed back? If so, how, if no, is there a way to hack into arrays already defined in the project, and modify them?

There is no mention of returning data in the SDK documentation that I can find, except for expressions.

Many thanks for any help.nutmix2013-07-23 13:23:30
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Tue Jul 23, 2013 4:10 pm

@nutmix

Using expression, check official websocket plugin, "expression:MessageText".
B
107
S
25
G
229
Posts: 4,349
Reputation: 130,384

Post » Tue Jul 23, 2013 4:35 pm

@rexrainbow - good tip.

I see that the flags are things like "ef_return_string". The is no ef_return_array. ef_return_any is an integer, float or string, according to the doc, so no way to return an array. I guess i could return JSON, or a coma separated string list, but parsing this is adding as much work than the plugin saves. I dont understand what ef_variadic_parameters are. These are designed for input, looks like the plugin system was not really designed to return data more complicated that a string or number. I need to return hundreds of numbers, unfortunately.

The plugin stuff looks very clever, but pretty bewildering and daunting as i don't have the time to invest to reverse engine it from examples.nutmix2013-07-23 16:36:36
B
17
S
6
G
3
Posts: 370
Reputation: 3,942

Post » Wed Jul 24, 2013 3:28 am

@nutmix

Yes, using JSON to pass array/hash table. There is a hash table plugin, you could use it to parse JSON string, or embed the parsing into your plugin.
B
107
S
25
G
229
Posts: 4,349
Reputation: 130,384

Post » Wed Jul 24, 2013 12:16 pm

@nutmix - look at the source to the Array object. Instead of returning all the values at once, it has expressions to tell you how many values are available, and then an expression to get the value at an index.

Conditions just return true/false directly from the condition method, and actions don't return anything.
Scirra Founder
B
381
S
222
G
84
Posts: 23,978
Reputation: 189,176

Post » Thu Aug 08, 2013 12:49 pm

Each plugin returns a packet of data, which is added to with a few defaults. Each plugin is guaranteed to always have the following data:
name:The name of the plugin. This is also the key in the array, of the full list of plugins, and is placed here since that is not always available.
module:The module that supplied the plugin.
file:The actual file containing the plugin.
path:The path to the file containing the plugin. This is useful for using secondary files, such as templates, css files, images, etc, that may come with a plugin.
By using this above the plugin return the data always
aliceria2013-08-27 11:06:45
B
1
Posts: 1
Reputation: 127

Post » Wed Aug 14, 2013 9:56 am

[QUOTE=rexrainbow] @nutmix

Using expression, check official websocket plugin, "expression:MessageText".[/QUOTE]
B
2
S
1
Posts: 6
Reputation: 314


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests