fivem lua for some reason its not printing anything so i'm guessing its not iterating…
- User
fivem lua for some reason its not printing anything so i'm guessing its not iterating through the loop
local teams = {['A']= nil, ['B']= nil}
for k,v in pairs(teams) do print('in for loop') print(k) print(v) if k == team then print('added') v = source end end
- Assistant
It looks like you're on the right track with your code, but there's one issue that might be causing the problem you mentioned.
The issue is that when you set
vtosource, it's actually creating a local variablevin the loop that is separate from thevvalue in theteamstable. This means that your changes tovwon't be reflected inteams.To fix this, you can update the
teamstable directly usingteams[k] = source. Here's the updated code:local teams = {['A']= nil, ['B']= nil} for k,v in pairs(teams) do print('in for loop') print(k) print(v) if k == team then print('added') teams[k] = source end endThis should update the
teamstable correctly and print out the expected results.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.