I
Irisss_54

Keys of dictionary

Firstly, as gdscript app states, we can't have the same key representing various values:

If so, why we have the same key " text" for a bunch of different lines?

Secondly, in the script:

Why do we put the variable "current_slide_index" as a key to the"slideshow_data"? What does the first line try to do? 

Why do we have to create a variable for the dictionary, is it the same as directly writing

set_text( slideshow_data["text"] ) ? 

  • Nathan Lovato replied

    If so, why we have the same key " text" for a bunch of different lines?

    This is because we have multiple separate dictionaries in an array. Each dictionary has only one key named text. A dictionary ends with the closing bracket character "}", So after that, if you open a new dictionary, you can reuse the same keys because it's not the same dictionary anymore.

    Why do we put the variable "current_slide_index" as a key to the"slideshow_data"? What does the first line try to do?

    The slideshow_data is an array that contains a list of dictionaries. Each dictionary in the array represents the data to display one slide. So the first step to display a slight is too fetch one dictionary from the slideshow_data array.

    To get a value from an array, we give the index of the desired value in square brackets. This index is contained in the variable current_slide_index, which is why we use it here.

    1 love