Help with Function Parameters.

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • In my .cap, I have a lot of objects whose properties I need to store in a array, something like Set Array(1) to ObjectA.X.

    Right now for each object, I have a long list of these and the only difference is the object they reference.

    What I'm trying to do, without luck, is to call a single function which picks these parameters and to change the object called using function parameters. Something like:

    Function: Add Parameter "ObjectA"

    Call Function "Properties"

    On Function "Properties"

    Set Array(1) Function.Param(1).X

    Set Array(2) Function.Param(1).Y

    So that Function.Param(1).X becomes ObjectA.X

    I'm guessing there a problem with the syntax, but I can't figure it out.

    Help would be most appreciated.

  • A function can be set to "ignore" or "remember" picked objects.

    When working with just one object type but many instances, just pick the proper instances and call the function set to "and remember picked objects"

    example:

    + Function: On function "props"

    -> myText: Set text to myObject.X

    + System: For each myObject

    -> Function: Call function "props" (and Remember picked objects)

    When working with different objects but the same object type (e.g. several different sprites) put them in a family.

    example (sprites put into family Blue):

    + Function: On function "props"

    -> myText: Set text to Blue.X

    + System: For each Blue

    -> Function: Call function "props" (and Remember picked objects)

  • Thanks for the reply.

    Yes, I'm aware of how functions work. What I have are multiple objects with multiple instances - that's why I thought of this kind of substitution. Using families does not help - in fact, it crashes Construct randomly...

    In general, I find families quite finnicky for more "complex" operations - I mainly use them to assign private vars to many objects...

  • If not using families you'll have to do it like this for each object type:

    On Function "Properties"

    System Compare: Function.Param(1) equal to "ObjectA"

    ----Set Array(1) ObjectA.X

    ----Set Array(2) ObjectA.Y

    System Compare: Function.Param(1) equal to "ObjectB"

    ----Set Array(1) ObjectB.X

    ----Set Array(2) ObjectB.Y

    But bear in mind that only the first instance of of a object type will be used. To get around that pass a second function parameter with the UID of the particular instance you want saved, and pick it with the "Pick by UID" condition.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • A little off-topic advice: Be careful not to have more than 15 (20?) function calls per tick/second, my game got a bit too heavy with them trying to keep code modular/seperate, and I ended up causing crashes every 5 minutes in my game.

  • Jayjay > sorry mate but I have to disagree with you.

    I made a maze generator 2 month ago and it's a recursive algorithm.

    I have the same function calling itself over and over.

    Yes it's buggy, but not because of so many function call, but because I call it inside a loop and CC seems to have hard time keeping track of them and doesn't end them properly.

    So I had to name the loops with a unique name. But even so, there can rarely be some random crash.

  • Function: Add Parameter "ObjectA"

    Call Function "Properties"

    just a nice tip for using function objects, this method will always remember picked objects I believe, but it's much simpler and more readable

    this here:

    Function: Add Parameter "somestring"

    Function: Add Parameter 1

    Function: Add Parameter 45

    Function: Add Parameter objecta.x

    Call Function "Properties"

    is equivalent to just doing this:

    all Function .Properties("something",1,45,objecta.x)

  • R0J0hound

    Yup, understood, but this is similar to what I have and am trying to avoid - multiple SetArray sequences with the only difference being the object referenced.

    The UID option might work though, iterating through Family members, but using the UID as the object identifier to pick up the data.

    Thanks.

    Jayjay and Yann

    Noted, thanks. I've ran into a similar issue - i needed to calculate the point of intersection of a line and an elipse centered on each of my object instances...

    No crashes, but it halved my framerate when dealing with only a hundred or so objects.

    lucid

    I didn't know about this shortcut - thanks.

  • all function -> .properties(param,param,...,param)

    keep in mind that this generates one extra function call, namely to the function: 0 (since the return value is 0), which actually can't be accessed since "call function" only takes a string as the parameter. To access it you must cast the function call to a string with str() like so: Call function -> str(.properties(param,param))

    Then when you make a condition [ On function: "0" ] It will perform the events because it calls the function called "0".

    Keep in mind that lucid's method is around 3x slower. Here's a benchmark I had made.

    <img src="http://dl.dropbox.com/u/1010927/Forumpics/F_bench.png" border="0" />

  • looks like davio is right, which was kind annoying, so I made a new function object. seems to be about 1.5 times the speed using the single expression method than the regular function object runs with the separate action method

    dl.dropbox.com/u/1013446/sharinplugs/func/plugins.rar

    dl.dropbox.com/u/1013446/sharinplugs/func/functest.cap

    this one will only accept the format:

    CallFunction :     .myfunctionname(param0,param1)

    there is no addparam, and callfunction does not pay attention unless you use that .functionname(params here) method

    or just .functionname if you have no parameters

    you get your params in one of two ways

    func.p(index)

    or just

    func(index)

    because it's easier to type p or nothing than param

    in this object parameters are 0 based, which means, the first parameter you put in is 0, the second is 1, etc

    this does not have the "on any function" or 'alias' features, but I can add them if anyone really uses them, and wants to use this faster function caller

    I would have just optimized the regular function object, but that code isn't on the svn

    let me know if anyone tries it, or if they encounter any bugs

  • Nice lucid! I was also kind of annoyed at that. I'll test it out soon.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)