@name DataSignal Test Send
@inputs CS:wirelink KB:wirelink Mem
@outputs 
@persist Cmd:string OldKB I
@trigger 

# IDK, BAD CODED, REWRITE

interval(10)

if(first())
{
    CS[2041] = 1
    dsClearGroups()
    dsJoinGroup("Chat")
    dsSetScope(2)
}

if(dsClk())
{
    Table = dsGetTable()
    
    CS:writeString(Table["Player",entity]:name() + ": " + Table["Msg",string],0,I)
    I++
    if(I >= 17){I = 0}
}

if(KB["Memory",number] & KB["Memory",number] != OldKB)
{
    
    if(KB["Memory",number] == 127)
    {
        Cmd = Cmd:left(Cmd:length()-1)
    }
    elseif(KB["Memory",number] == 13)
    {
        Tabl = table()
        Tabl["Player",entity] = KB["User",entity]
        Tabl["Msg",string] = Cmd
        dsSend("Msg","Chat",Tabl)
        Cmd = ""
    }
    elseif(KB["Memory",number] == 154)
    {
    }
    else
    {
        Cmd += toChar(KB["Memory",number])
    }
    CS[2039] = 17
    CS:writeString(Cmd,0,17)
}

OldKB = KB["Memory",number]
