Function Names

This forum is currently in read-only mode.
  • Functions

    When I add a function parameter then use that parameter for an event, it doesn't register.

    Something like:

    Button Clicked -> Add Paramter 2 (an integer)

    if Function.Param(1) == 2 -> do something

    it doesn't do something..

    However, if I do this:

    Button Clicked -> Add Paramter "something" (a string)

    if Function.Param(1) == "something" -> do something

    it works!

    So is this a bug or am i doing something wrong

  • Can you post a screen of your actions, or copy as text this part of event list? Or maybe cap.

  • Functions

    When I add a function parameter then use that parameter for an event, it doesn't register.

    Something like:

    Button Clicked -> Add Paramter 2 (an integer)

    if Function.Param(1) == 2 -> do something

    it doesn't do something..

    However, if I do this:

    Button Clicked -> Add Paramter "something" (a string)

    if Function.Param(1) == "something" -> do something

    it works!

    So is this a bug or am i doing something wrong

    You shouldn't rely on a function parameter being accessible through events. You don't know how they are stored internally, converted, etc. Those parameters are always accessible within a function and you can rely on that. But for a structure like the one of your example you have global and private variables.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yea. I think it was bad practice that I was trying to compare the parameter using system function and as an event..hmm, maybe I should try assigning the parameter to a global variable and then use it for an event condition.

  • ...I was trying to compare the parameter using system function and as an event..

    Not to confuse you, but this is possible ...as long as it is done within the function declaration. For example:

    +On function "test"

    ++function.param(1) equal to 2

    ->Set text to "yes it works"

    +timer is equal to 5000

    ->add parameter 2

    ->call function test

    Assuming there's a textbox and a function object in the layout, this will set the text to "yes it works" after 5 seconds have passed.

    This means, if you want some kind of a central point to manage a menu or something like that, you could set up a function that will test for all possible values:

    on function "selector"
        function.param(1) equal to 1
                                                    ->do menu 1 option
        else
        function.param(1) equal to 2
                                                    ->do menu 2 option
        else
        function.param(1) equal to 3
                                                    ->do menu 3 option
    
    on left clicked on red sprite
                                                    ->add parameter 1
                                                      call function "selector"
    on left clicked on green sprite
                                                    ->add parameter 2
                                                      call function "selector"
    on left clicked on blue sprite
                                                    ->add parameter 3
                                                      call function "selector"[/code:25xuhyac]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)