我有一个具有动态键和值的表,我想用一个泛型的for循环来循环它,但是,由于表值是动态的,我如何获得动态变量的值?我希望这是有意义的。让我用代码演示一下,以便更好地解释。
Local weapons = {
[GetHashKey('WEAPON_PISTOL')] = { [Strings['supp_name']] = GetHashKey('component_at_pi_supp_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_PISTOL_VARMOD_LUXE') },
[GetHashKey('WEAPON_PISTOL50')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_PISTOL50_VARMOD_LUXE') },
[GetHashKey('WEAPON_COMBATPISTOL')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_PI_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = nil },
[GetHashKey('WEAPON_APPISTOL')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_PI_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_APPISTOL_VARMOD_LUXE') },
[GetHashKey('WEAPON_HEAVYPISTOL')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_PI_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_HEAVYPISTOL_VARMOD_LUXE') },
[GetHashKey('WEAPON_VINTAGEPISTOL')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_PI_SUPP'), [Strings['flash_name']] = nil, [Strings['grip_name']] = nil, skin = nil },
[GetHashKey('WEAPON_SMG')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_PI_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_SMG_VARMOD_LUXE') },
[GetHashKey('WEAPON_MICROSMG')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_PI_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_MICROSMG_VARMOD_LUXE') },
[GetHashKey('WEAPON_ASSAULTSMG')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = nil, skin = nil },
[GetHashKey('WEAPON_ASSAULTRIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = GetHashKey('COMPONENT_ASSAULTRIFLE_VARMOD_LUXE') },
[GetHashKey('WEAPON_CARBINERIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = GetHashKey('COMPONENT_CARBINERIFLE_VARMOD_LUXE') },
[GetHashKey('WEAPON_ADVANCEDRIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = nil, skin = GetHashKey('COMPONENT_ADVANCEDRIFLE_VARMOD_LUXE') },
[GetHashKey('WEAPON_SPECIALCARBINE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_BULLPUPRIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_ASSAULTSHOTGUN')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_HEAVYSHOTGUN')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_BULLPUPSHOTGUN')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_PUMPSHOTGUN')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_SR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = nil, skin = nil },
[GetHashKey('WEAPON_MARKSMANRIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP'), [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil },
[GetHashKey('WEAPON_SNIPERRIFLE')] = { [Strings['supp_name']] = GetHashKey('COMPONENT_AT_AR_SUPP_02'), [Strings['flash_name']] = nil, [Strings['grip_name']] = nil, skin = nil },
[GetHashKey('WEAPON_COMBATPDW')] = { [Strings['supp_name']] = nil, [Strings['flash_name']] = GetHashKey('COMPONENT_AT_AR_FLSH'), [Strings['grip_name']] = GetHashKey('COMPONENT_AT_AR_AFGRIP'), skin = nil }
}
local Strings = {
['removed_supp'] = 'You removed your suppressor',
['removed_grip'] = 'You removed your weapon grip',
['removed_flash'] = 'You removed your weapon flashlight',
['no_fit'] = '%s does not fit your current weapon',
['removed'] = 'You have removed your %s',
['used'] = 'You have used your %s',
['webhookMSG'] = '**Spiller Navn:** %s \n**ID:** %s \n**Tried to spawn:** %s',
['supp_name'] = 'suppressor',
['supp_Rname'] = 'Suppressor',
['supp_desc'] = 'Can be used to make your weapon silent when shooting.',
['flash_name'] = 'flashlight',
['flash_Rname'] = 'Flashlight',
['flash_desc'] = 'Can be attached to a weapon to give it a flashlight.',
['grip_name'] = 'grip',
['grip_Rname'] = 'Grip',
['grip_desc'] = 'Can be attached on a weapon to get a better grip.',
['choice_use'] = 'Use'
}正如您在表中看到的,这些值依赖于Strings表中的值。所以,如果我想做一个for循环,并得到正确的值,我将如何做呢?
for k,v in pairs(weapons) do
if k == GetHashKey('WEAPON_PISTOL') then
print(v.<what here>) -- how do i get the v.Strings['supp_name']?
end
end我希望这是有意义的,如果没有,请在评论中询问。
谢谢你,奥斯西
发布于 2022-01-18 08:34:41
只需使用v[Strings['supp_name']]
https://stackoverflow.com/questions/70748245
复制相似问题