Generating a function from a variable

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hiki Hollow

I’ve sort of hit a brickwall with what i’ve wrote.

The code is composed of two parts:

  1. Load levels (name, texture, true/false) into ItemList
  2. Generate change scene pointers dynamically based on ItemList entries.



  1. First Part
  2. Second Part

The second part gets called by a button click and run into this problem.

Should I rewrite the variable to look like a function for it to work? That sounds like a very round-about way of doing things, so if anyone could propose a better solution, it’d be appreciated.

:bust_in_silhouette: Reply From: Dlean Jeans

call() can only call functions, not scripts. To run scripts you would need to do something like this. Quite complex for what you’re trying to achieve.

I think you can write like this and probably throw away your genTelelist():

func _on_ItemList_item_selected(index):
  var scene_path = levelData[index]

I was at first on similar path, but for some reason didn’t end up working. Seems your idea was still the correct and simpler way of doing things. Thanks for that.

This ended up working:

func _on_ItemList_item_selected(index):
   var scene_path = levelData[index]

Also, thanks for the link. This might prove useful later!

Hiki Hollow | 2019-06-29 20:05