Null values in Lists

gruffman

  • *
  • Posts: 564
I have a LIST of data, that may not have values in all fields, eg

1
3
null
5
6
null
7

I only want to use the fields that have data in. But I can't seem to reference the `null` fields so that I can accurately avoid using them. For example, this does not work



Any ideas on how to accurately gauge which fields are empty so i can ignore them? Reordering the list in any way is not a possibility.
Now available for all Android Devices - Happy Face Concentration
My Games To Date
Find A Face / Hero Of Oda / Snakes And Ladders
Hungry Monkey available at fgl.com for Sponsorship
My site - Gruffgames.com

JasonIrby

  • Posts: 290
I ran into this also.  Interested in the solution.

-Jason

rob1221

  • *
  • Posts: 9473
Does it work with the "__ as text" block?

Hectate

  • *
  • Posts: 4643
Are you in 3.0? Haxe has a special "null" type for this I believe...

http://haxe.org/ref/syntax
Quote
Notice that null has a special value, since any value can be null.
but it behaves differently depending on circumstances:
http://haxe.org/manual/basic_types
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

gruffman

  • *
  • Posts: 564
Does it work with the "__ as text" block?

Sadly not, worth a try though.
Now available for all Android Devices - Happy Face Concentration
My Games To Date
Find A Face / Hero Of Oda / Snakes And Ladders
Hungry Monkey available at fgl.com for Sponsorship
My site - Gruffgames.com

gruffman

  • *
  • Posts: 564
Are you in 3.0? Haxe has a special "null" type for this I believe...

http://haxe.org/ref/syntax
Quote
Notice that null has a special value, since any value can be null.
but it behaves differently depending on circumstances:
http://haxe.org/manual/basic_types

I am in 3.0 but my Haxe skills = 0.
Now available for all Android Devices - Happy Face Concentration
My Games To Date
Find A Face / Hero Of Oda / Snakes And Ladders
Hungry Monkey available at fgl.com for Sponsorship
My site - Gruffgames.com

Tuo

  • *
  • Posts: 2469
Umm, FYI, your example would not work. Lists start at an index of 0, so the "item 3" is actually the 5 from the list.

I personally use 0's for null values and have never had issues with them... *shrugs*
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

Justin

  • *
  • Posts: 4716
Gruffman, your example is close. Just enclose "null" in a code block. As it is, Stencyl will think that you're comparing against the string "null" rather than the null value.
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)

Jubiloo87

  • Posts: 1
I have a similar question, and I'd rather not post my very own topic for what seems like it may be the same solution.

I'm using a list for a dialogue system that pulls 4 lines of text at a time from a list and types out what that item says. However if one of those lines does not havea  value it returns as "UNDEFINED" and prints that.

What I'm trying to figure out is if there is some way to check if the current item in a list has no value so I can tell my text typer not to display text if no value = true. Sounds simple enough but I can't for the life of me figure it out.

Thanks!

Justin

  • *
  • Posts: 4716
Jubiloo, assuming you're using 2.2, I think that in your case it will be a little more difficult, because of the specific way that equality is checked in the flash engine.

Stencyl uses Script.sameAs() to check for equality, which immediately returns false if either of the values is null or undefined. Instead you could try the following in a code block:

Code: [Select]
_YourArrayName[0] != null
If you use that as the boolean in your if statement, it will only pass through if the first element (index 0) of "Your Array Name" is defined.



Actually... upon second thought, you could just compare the value against itself. If Stencyl equality check returns false, then at least one of the values must have been null.

Code: [Select]
if <[get item # [0] from [Your List] = [get item # [0] from [Your List]>
- ...
For Live Support: Join our discord server and ping me @justin.
I'm most often available between 10am and 10pm Japan time. (GMT+9)