How do I compare a variable to null

0 favourites
  • 10 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi,

    I have a variable returned from an AJAX call that might be null. How do I compare this variable to null & redirect when the variable is null?



  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • There's a system condition "If number is NaN" that you can use to check.

  • sorry, I should have been more specific. The variable is named "returnPage" & is a string.

  • dang it, I can't figure out how to insert an image here to help explain what I'm trying to do. I'll try English

    On touched resultsHomeButton

    if returnPage is null

    go to "MissionChallenges.aspx" (target self)


    go to returnPage (target self)

    but Construct 2 shows (not valid here) next to my else. How do I get this to work? Again, the returnPage variable is returned from an AJAX call in a JSON object, & the server might return null for that variable...

  • RealityMasque

    Is that null as in no value or an empty string?

    If it's an empty string, doing System-Compare two values: returnPage = "" should do it.

    Otherwise, not sure if this will work, but maybe System-Compare two values: "" & returnPage = ""

  • It's actually null, because the current javascript that simply redirects to returnPage refreshes the page when it does window.location.href = returnPage.

  • RealityMasque

    Just remembered something that works with boolean instance variables is the expression Object.BooleanVar ? "true" : "false"

    I wonder if that would work for the comparison here


    System-Compare two values: returnPage ? "notNull" : "null" = "null"

    EDIT: Had a quick look in the Editor, there is a System-Is value type condition, which you could use to see if returnPage is a string

  • well, it looks I can do that, but the else is still saying (not valid here)

  • well, it looks I can do that, but the else is still saying (not valid here)

    I've just tried adding an Else event following the System-Is value type event, and that works, so not sure where you're putting your else to get that error.

    If you can't get the else to work, do another event with the same condition, but invert it (right-click, select Invert).

  • You are probably trying to use an "else" statement on a trigger. This won't work.

    See the difference here :

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