How do I properly test for NULL in c2

0 favourites
  • 4 posts
From the Asset Store
Soldier Test
$9.99 USD
A Construct version 2 & 3 "Stand-alone" RPG game with "In-Game Module" (IGM) integration.
  • functions have a habit of returning "" or 0 on failure, and this is a lot different than a null.

    What is the equivalent of "if value == NULL" in C2?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There is no NULL in C2. Where would you want to test for NULL?

    The only example I can think of is when using the find() expression. It will return -1 if the text can't be found.

  • There isn't one unfortunately... C2 doesn't have any referencing for "null" values. For official plugins everything is forced to Numbers, Strings or Boolean. nulls are usually returned as int(0) and then converted to what ever you are setting to.

    Example:

    You have a var myString that you set from a function return and some how that return value is null (shouldn't be possible unless using a 3rd party plugin) this would be the resulting outcome.

    var myString = ""; (defined as type string)

    myString = myfunction.returnValue; (set myString from function return value. if null it will return int(0))

    myString equals "0" (stringified version of int(0))

    Based on looking at the plugins this appears to be by design to either prevent system errors or non-programmers from making mistakes. We just have to work around this limitation.

  • This complicates things since empty strings and 0s are valid values in a lot of cases. I've been setting my own Functions to return -1 but if the compare dialog had a NULL option it would be VERY useful. Null is important imo. At least in the way my brain thinks.

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