Fretta, setting variables for each time during game
6 replies, posted
I'm making a gamemode where one player can buy upgrades for his team. Unlock extra tiers of equipment, etcetera. Can anybody tell me how I'd keep track of this? Once I get storing variables down, the rest won't be a problem. I imagined it would be as simple as ply:Team().tieroneunlocked = true but doesn't ply:Team() only return an enumeration? I haven't test this yet but I have the feeling it'll just error. Can anybody shed some light?
You cant add a variable to a team, because ply:Team() just returns a number but you could have a global table like so
[lua]teamtable = {}
function SetTierOne(ply)
teamtable[ply:Team()].tieroneunlocked = true
end[/lua]
[QUOTE=CmdrMatthew;27938363]You cant add a variable to a team, because ply:Team() just returns a number but you could have a global table like so
teamtable = {} function SetTierOne(ply) teamtable[ply:Team()].tieroneunlocked = true end[/QUOTE]
Yeah, that's what I ended up doing. Almost verbatim. I eventually ended up with unlocked[ply:Team()][category]=tier So shotguns tier 3 would be unlocked[ply:Team()]["shotguns"]=3
Teams ain't some kinda entity or place to store stuff in. Store stuff using tables:
[lua]
TeamTables = {}
function team.Store(team, ind, var)
TeamTables[team][ind] = var
end
function team.GetStore(team, ind)
return TeamTables[team][ind]
end
[/lua]
This could be properly made with metatables I think, but I cba that.
[QUOTE=Donkie;27951832]Teams ain't some kinda entity or place to store stuff in. Store stuff using tables:
[lua]
TeamTables = {}
function team.Store(team, ind, var)
TeamTables[team][ind] = var
end
function team.GetStore(team, ind)
return TeamTables[team][ind]
end
[/lua]
This could be properly made with metatables I think, but I cba that.[/QUOTE]
Attempt to index ? a nil value.
[QUOTE=|FlapJack|;27952365]Attempt to index ? a nil value.[/QUOTE]
get out
It was a example :P
[lua]
local teaminfo = {}
debug.setmetatable(0,{
__index = function(i,k) return teaminfo[i] and teaminfo[i][k] end,
__newindex = function(i,k,v) teaminfo[i] = teaminfo[i] or {} teaminfo[i][k] = v end
})
[/lua]
Sorry, you need to Log In to post a reply to this thread.