[SOLVED] Maps and Null object reference error - but the game works

dtishin

  • *
  • Posts: 89
Hi all, I'll appreciate some info on this :)

I access a key ("name") of a map-type actor attribute ("monster selected") in a "creating" event.
When I test the game I get the "Null object reference" error.
Still, if I dismiss the error pop-ups, the code works as intended.
What is causing the error message, and how do I make sure it doesn't pop up?

Please see a screenshot of the game test (with monster names actually drawing in the scene) and the code attached.

Thanks!

« Last Edit: May 02, 2019, 02:50:59 pm by dtishin »

Luyren

  • *
  • Posts: 2735
First guess: lists and maps that are hidden must be initialized (set to "create new list" and "create new map" respectvely) before you can access any data on them.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter

dtishin

  • *
  • Posts: 89
First guess: lists and maps that are hidden must be initialized (set to "create new list" and "create new map" respectvely) before you can access any data on them.

I know about hidden lists, so I don't normally hide any maps or lists, please see attached. I had also added a default pair of (key + value) just in case, so that it doesn't consider it empty when compiling (though I have no clue what happens under the hood).

dtishin

  • *
  • Posts: 89
First guess: lists and maps that are hidden must be initialized (set to "create new list" and "create new map" respectvely) before you can access any data on them.
Thanks Luyren, the error disappeared as soon as I initialised all lists and maps when created.
It seems that it doesn't matter if they are hidden or not!

Luyren

  • *
  • Posts: 2735
Glad to hear that!
Just for the record: I think it's good practice to only make unhidden lists/maps if you are going to populate those. If they are populated, you don't need to initialize those.
My Stencyl resources are available here: https://luyren.itch.io/
Cutscenes, RPG Elements, Particles, Map System and many more.
Twitter