Tutorial Feedback | Setting Defaults for Function Parameters

0 favourites
  • 1 posts
From the Asset Store
Carousel Animation, make carousel of you image gallery or anything
  • Hello everyone,

    For some time I've been wanting to try and make some video tutorials for Construct. I did this one kind of spur of the moment and would like some feedback on it, such as on ease of watching, actually learn something, voice, visuals, etc.

    Also, the topic of parameter defaults was something I just figured out that day so if anyone has any information to add or counter-points please let me know, as I hope I'm not giving people bad info.

    Here it is:

    Setting Defaults for Function Parameters in Construct

    Subscribe to Construct videos now

    link: youtu.be/Tk8TLNS06p4

    How to set a function default in Construct.

    Using a ternary operator you can easily create a default for a function parameter. To increase readability in complex functions I like to create a local variable in the function, but if only using the parameter once you can skip this step.

    set localVariable to: Function.Param(0) ? Function.Param(0) : "default fallback"

    If a parameter is passed to the function the local variable will be set to this parameter. If no parameter is passed then a default can be used.

    Use Case Example:

    Lets say you are making a simple game such as a space shooter like Galaga or classic platformer like Mario where when you get hit by an enemy it always does the same thing—lets just call it damage of 1. So you make a function to call whenever this damage is done, as you may need to perform multiple actions such as updating a HUD. Later in game development you create a more powerful enemy that you want to do more damage or something different. You could create a separate function or go back and add all the previous function calls to pass a parameter of 1 (as in 1 damage done). Or you could use this default method to have 1 damage be reduced whenever no parameter is passed but this allows you to pass a parameter (of 2 or 3) when that more powerful enemy damages the hero.

    Also, if anyone wants to let me know if this has the same result in Construct 3 as in Construct 2 that would be helpful, as I've already been asked that.

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)