I want to orient the next value or key without utilizing functions. Like this but without functions.
local GrenadeModes = {
["Grenade"] = function()
return "Fire"
end,
["Fire"] = function()
return "TG"
end,
["TG"] = function()
return "Grenade"
end,
}
--Default value is Grenade
Config.HKData.CurrentMode = GrenadeModes[Config.HKData.CurrentMode]()
1 Like
Figured I can just do this. But is there any better ways?.
local GrenadeModes = {
["Grenade"] = "Fire",
["Fire"] = "TG",
["TG"] = "Grenade"
}
2 Likes
local GrenadeModes = {"Grenade", "Fire", "TG"}
local currentGrenade = 1
function nextMode()
local maxNum = #GrenadeModes
local newMode
currentGrenade += 1
if currentGrenade <= maxNum then
newMode = GrenadeModes[currentGrenade]
else
newMode = GrenadeModes[1]
end
Config.HKData.CurrentMode = newMode
return currentGrenade, newMode
end
Config.HKData.CurrentMode = GrenadeModes[1]
--call nextMode() to switch to next mode. Values received: 1 = number (Grenade = 1, Fire = 2, TG = 3) | 2 = name of mode
you can add more modes without needing to modify the function
I understand that you didn’t want to utilise functions, and to have the current values as the next in the table but allows for convenience
please do tell me what Config.HKData.CurrentMode is - I judged it as a number based off of your example
1 Like
this is what it is.
return {
HK = true,
HKData = {
CurrentMode = "Grenade",
Fire = {
DebugMode = "Fire"
},
Grenade = {
DebugMode = "Grenade"
},
TG = {
DebugMode = "TG"
}
},
}
1 Like
edited, now it should fit
1 Like