AllConfigValues
This function was added in DSL 1
Description
Returns an iterator function designed for use in a for loop that returns each value associated with key
.
Iterates over all values in a configuration object for a given key. This function is useful for retrieving all values associated with a specific key in a configuration, allowing for easy access to multiple values without needing to know the exact structure of the configuration.
function AllConfigValues(config, key) --[[ ... ]] end
Parameters
config
:userdata
- The configuration object to iterate over.key
:string
- The key to look up in the configuration.
Return Values
iterator
:function
- An iterator function that returns the next value in the configuration for the given key.
Example
Give the player each weapon listed in a gConfig
, which is presumed to already exist as a Config
object.
script
for weapon in AllConfigValues(gConfig, 'weapon_model') do
local model = tonumber(weapon)
if model then
PedSetWeapon(gPlayer, 50)
else
PrintWarning('expected number for weapon ('..weapon..')')
end
end
config
# List as many weapon models as you want to be used with AllConfigValues
weapon_model 301 # fire crackers
weapon_model 305 # spud gun
weapon_model 307 # bottle rocket launcher