gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
fivem scripting local teams = {['A']= 0, ['B']= 0} for k,v in pairs(teams) do if v == 0…
- User
fivem scripting
local teams = {['A']= 0, ['B']= 0}
for k,v in pairs(teams) do if v == 0 then trigger event end end
how do i only get the event to trigger if the v == 0 for both 'A' and 'B'
- Assistant
You can use a counter variable to check if both values of 'A' and 'B' are 0:
local teams = {['A'] = 0, ['B'] = 0} local zeroCount = 0 for k, v in pairs(teams) do if v == 0 then zeroCount = zeroCount + 1 end end if zeroCount == 2 then -- Trigger event end - User
is the most optimal way to do it?
- Assistant
A more optimal way would be to check the values of 'A' and 'B' directly, since there are only two keys in the table. This way, you don't need a loop and an additional counter variable:
local teams = {['A'] = 0, ['B'] = 0} if teams['A'] == 0 and teams['B'] == 0 then -- Trigger event endThis code is simpler and more efficient because it directly checks the values of 'A' and 'B' in the
teamstable.