scripted_gui = {
   scripted_gui_example_9 = {
       context_type = player_context
       window_name = "scripted_gui_example_9"

       visible = {
           check_variable = { global.current_example = 9 }
       }

       # This array stores the progress for each entry.
       # We also use a variable to keep track of how many entries exist.
       on_open = {
           if = {
               limit = { NOT = { is_variable_set = example_9_entry_count } }
               set_variable = { example_9_entry_count = 0 }
               clear_array = example_9_progress_array
           }
       }

       dynamic_lists = {
           state_grid = {
               # This special syntax creates a list from 1 up to the value of the variable.
               # It gives us a simple way to create N entries without needing an array of scopes.
               array = "1..example_9_entry_count"
               change_scope = no # We are not changing scope, the value is just a number.
               # The index of the loop is stored in 'i' (0-based)
               # The value of the loop is stored in 'v' (1-based in this case)
               entry_container = scripted_gui_example_9_state_entry
           }
       }

       effects = {
           # The 'add' button now simply increments our counter and adds a new '0' entry to our progress array.
           button_add_click = {
               add_to_variable = { example_9_entry_count = 1 }
               add_to_array = { example_9_progress_array = 0 }
           }

           # This button is in each entry. It adds progress to the corresponding index in the progress array.
           # This is the repurposed "remove" button.
           button_remove_click = {
               # 'i' is the 0-based index of the entry that was clicked.
               modify_array = {
                   array = root.example_9_progress_array
                   index = i
                   operation = add
                   value = 10
               }
           }
       }

       triggers = {
           # This trigger is evaluated for each list entry every frame. We use it to set up temporary
           # variables that the GUI elements can then use.
           button_progress_click_enabled = {
               # This sets a temp variable for the entry's name. We add 1 to the index to get "var_1", "var_2", etc.
               set_temp_variable = { entry_display_index = i }
               add_to_temp_variable = { entry_display_index = 1 }
               
               # This gets the current progress value from our array using the entry's index.
               set_temp_variable = { current_progress = root.example_9_progress_array^i }

               # We also check if the bar is full to disable the button.
               check_variable = { current_progress < 100 }
           }
       }

       properties = {
           # Here we link the temporary variables from the trigger to the GUI elements.
           entry_name = {
               # This creates the text "Var_1", "Var_2", etc.
               text = "Var_[entry_display_index.GetValue]"
           }
           entry_progress_bar = {
               # This sets the value of the progress bar.
               value = current_progress
           }
       }
   }
}