WOlfen wrote: ↑21 Sep 2020, 11:49
(...)
Here i want that the script converts the "SubVariables" of "EngineList", so it looks like this:
EngineList = Apple|People|Unity 2.5|Music|RPGMaker|Car|Unreal Engine|Movie
The Script at the same time should still allow me to use the "SubVariables", so
msgbox, %RPGMaker% would still return
"NormalPlay" "ShowTitle" "Window"
In this case you might need to build an
associative array - here's a commented example:
Code: Select all
EngineList =
(Join`n Comment
Apple = ;stuff for the script
People = ;other stuff for the script
Unity 2.5 = -screen-width 3440 -screen-height 1440
Music = ;stuff for the script
RPGMaker = "NormalPlay" "ShowTitle" "Window"
Car = ;stuff for the script
Unreal Engine = test
Movie = ;again other stuff for the script
)
substrings := StrSplit(EngineList, ["=", "`n"], A_Space)
; separate EngineList into an array of substrings using both the '=' and '`n' (linefeed) as delimiters
; the StrSplit function returns an array (object) of strings - that is: ["Apple", "", ...., "RPGMaker", "NormalPlay" "ShowTitle" "Window"", ..., "Movie", ""]
config := Object(substrings*)
; create an associative array from the array. An associative array is a collection of unique keys and a collection of values, where each key is associated with one value
; the wilcard indicates to the script here:
; 1° that we don't want to pass a reference to the array nor the array as a list of parameters (use its elements as parameters).
; 2° that the number of parameters hence depends on the total number of elements in the array: it is variadic.
; since we passed all substrings' elements as parameters here, keys will be entries such as RPGMaker and values their respective value in the EngineList variable - something like this:
; {"Apple": "",... , "RPGMaker": "NormalPlay"" ""ShowTitle"" ""Window",... , "Movie": ""}
; but without hard-coding it here
; alternatively, you can build config like this (less cryptic):
config := {}
for each, value in substrings
{
if (mod(a_index, 2)) ; if a_index is odd...
lastFoundValue:=value ; save the key for the next iteration...
else config[lastFoundValue] := value ; associate the key to a value
}
keys := ""
for key, value in config
{
; MsgBox % key "," value
keys .= "|" key
}
; Some code here
Gui, Add, DropDownList, x170 y69 w200 vEngine1 glabel, % keys
GUI, Show, AutoSize
return
label:
GuiControlGet, selectedItem,, % A_GuiControl
; if (config.hasKey(selectedItem))
ToolTip % config[selectedItem] ; use the brackets to retrieve an item from the associative array
return
hope this helps
A_AhkUser
[addendum]:
If sometimes an equal sign appears in the value (cmd params) associated with a key (engine), on might need to use something like the following instead:
Code: Select all
config := {}
Loop, parse, EngineList, `n ; retrieves substrings (fields) from EngineList, one at a time, using the linefeed as delimiter
{
parts := StrSplit(A_LoopField, " = ", A_Space, 2)
; split each field itself:
; 1° using the equal sign as delimiter
; 2° excluding from the beginning and end of each element trailing space(s), if need be
; 3° returning at most 2 substrings, even if there's more than one equal sign in the field: the remainder of the string being returned in the second substring
config[ parts.1 ] := parts.2
}
keys := ""
for key, value in config
{
; MsgBox % key "," value
keys .= "|" key
}
Gui, Add, DropDownList, x170 y69 w200 vEngine1 glabel, % keys
GUI, Show, AutoSize
return
label:
GuiControlGet, selectedItem,, % A_GuiControl
; if (config.hasKey(selectedItem))
ToolTip % config[selectedItem] ; use the brackets to retrieve an item from the associative array
return
A_AhkUser