referencing undefined/null

0 favourites
  • 4 posts
  • How do I reference undefined or null? I want to check if an array contains any elements that have a value of undefined/null. I know you would use the contains value block, but I don't know how to put undefined/null in.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • By default, an undefined cell contains a value of 0. Values outside of the array dimensions also result in 0.

    You can enter your own string or value that you don't plan on using otherwise to define an undefined cell, and compare values to look for your specified value/string.

    For example, in my game I wanted to differentiate between empty or out of bounds in my array. Since I did not plan to use negative values, I filled the array with -1 on start of layout. Then I could compare to see that -1 was empty, 0 was out of bounds, and anything else was a valid data value.

  • Construct's event system doesn't have an undefined or null type. It shouldn't normally be possible to write such a value to an array either with the event system.

    If you're reading external data with null or undefined in it, then Construct will report those as the number 0 (IIRC). If you need to read all JavaScript-compatible data types then you'll probably need to write code or change the data format.

  • Thanks that solves my problem, as I wanted to convert all null/undefined values to 0 from an array when I import in using AJAX.

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