Generally use function parameters & passes?

0 favourites
  • 4 posts
From the Asset Store
Assets for creating mountains and ravines environments
  • As a noob I never venture to put parameters in my functions, which in turn usually leaves some ugly, naked parenthesis.

    What world am i missing out on here? The tutorials dont really explain. For example:

    Function “create ball” (ball, color)

    On function “create ball”: create object ball; color ( blue) ..... is this just some form of picking that works better than picking? Are object instance variables just as “good” ?

    Thanks so much.

    Grog

  • Functions in construct are a little different than traditional functions... So parameters are mainly an organizational/visual way to pass information/variables to a function. They are basically the same as local variables unique to each call of the function.

    It doesn't really have anything to do with picking, but yes functions can access instance variables just fine so there isn't much difference there. For example, sometimes you want to use parameters to set the instance variable in the first place, if your function is creating an object.

    They basically allow your functions (a common set of actions used in multiple places in your project) to be more flexible in what they can do, so you don't have to keep remaking a similar set of actions that are just slightly different for many events.

    When your projects get larger, functions are an valuable organizational tool.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On function “create ball”: .........

    Using your example and slightly changing it

    you have a ball sprite with 3 animation frames of different colors of the ball (say 0, 1, 2 = red, blue, green)

    and your function event is

    On function" create ball"

    • Create Sprite Ball
    • set size to function parameter 0
    • set animation frame to function parameter 1

    then the calls in your game events could be

    call "create ball" (10, 2)

    will give you a small green ball

    call "create ball " (100, 0)

    will give you a medium size red ball

    for "" 0 to 1

    • call "create ball" (1000, 1)

    will give you two giant blue balls

  • Hahaha that’s GREAT!

    From that example a function can serve as a great shorthand writing style to perform a bunch of actions (resulting in much less clutter in the events page).

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