Function APIs

Ashley's avatar
Medal
Construct Team Founder
Published 19 Sep, 2018
163 words
<1 min

When the Function plugin is present in a project, it creates a global function that can be used to invoke a function from JavaScript. Note this function does not exist if the Function plugin is not present in the project, so calling code should check for the existence of the method first. An example is included below.

if (self.c2_callFunction)
    self.c2_callFunction("name", ["param1", "param2"]);

self.c2_callFunction(name, params)

Synchronously trigger the function with the given name in the event system. params is optional and can be omitted if no parameters are to be passed; otherwise it must be an array of the parameters to pass. Parameters may only be string or number primitives - any other types will return as 0 in Construct. If the function in the event system returns a value, it is also returned by this method, and also can only return a string or number primitive.