Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· openaiHugging Face Suzhen/CodeChat

fivem lua for some reason its not printing anything so i'm guessing its not iterating…

  1. 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

  2. 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 v to source, it's actually creating a local variable v in the loop that is separate from the v value in the teams table. This means that your changes to v won't be reflected in teams.

    To fix this, you can update the teams table directly using teams[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
    end
    

    This should update the teams table correctly and print out the expected results.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.