1. I tried to loop trough the args of a chat command, but my problem is, instead of adding the current arg to the string, it replaces it.
    If I do the Command like this: /test 1 2 3
    Using my code It should be in the chat like this:
    1
    1 2
    1 2 3
    but it looks like this:
    1
    2
    3

    This is my code:
    Code:
        local allArgs = ""
        local arg = args:GetEnumerator()
        while arg:MoveNext() do
            local allArgs = allArgs .. " " .. arg.Current
            rust.SendChatMessage(player, allArgs)
        end
    what am I doing wrong?
    The rust.SendChatMessage() is for debugging
     
  2. You are initialising a new allArgs variable in every loop.
     
  3. but I mean the
    local allArgs = ""
    is outside of the loop, isnt it?
     
  4. Yes, but you are setting a new local allArgs for every loop.
     
  5. umm I mean basicly what i want to do is, get the arg as string, then for the next arg, I want to set that arg, as that already saved args + the current Arg
    so thats what i basicly done. Whats wrong with that logic?
     
  6. Wulf

    Wulf Community Admin

    Code:
       local allArgs =""
       local arg = args:GetEnumerator()
       while arg:MoveNext()do
           allArgs = allArgs .." ".. arg.Current
           rust.SendChatMessage(player, allArgs)
       end
     
  7. umm what you have done is removing some spaces?
    Does that really affect that?
     
  8. Wulf

    Wulf Community Admin

    Spacing does not matter, I made the change mentioned by Domestos.
     
  9. What I can see is that you removed the "local". Why doesn't that work with "local"? :eek:
     
  10. Wulf

    Wulf Community Admin

    Because you are resetting that variable each time you run it in the loop instead of pulling in what it stored the previous loop via the local outside.
     
  11. umm okay thanks