I have a Script which listens for 'modem_message' events and to get track about 'Clients' i have a same named Table where i want to add each client-robot to it...
The Code looks reduced like:
Reveal hidden contents
local component =require("component")localevent=require("event")local wlan = component.modem
local wlanPort =7331
wlan.open(wlanPort)localClients={}function tableLength(T)local count =0for k,v in pairs(T)do count = count +1endreturn count
endfunction addClient(remoteAddress)local rcount =(tableLength(Clients)+1)Clients[rcount]= remoteAddress
print("Added new Client #"..rcount)endfunction messageReceived(event, localAddress, remoteAddress, port, senderDistance, message)
addClient(remoteAddress)endevent.listen("modem_message", messageReceived)whiletruedo
os.sleep(1)end
The Problem is that 'rcount' doesnt get expanded. Its always same
It receives a modem_message, so the event works - thats tested and is not the Problem. Also i know that #Clients can return the table length too but i have a good reason why i did it not that way (#tbl only works for numerical keys)
What am i doing wrong?
//EDIT: the reduced code works... mmh why not the real?
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
I have a strange behavior with an Table ...
I have a Script which listens for 'modem_message' events and to get track about 'Clients' i have a same named Table where i want to add each client-robot to it...
The Code looks reduced like:
Real code: http://pastebin.com/hfjT7e8s
The Problem is that 'rcount' doesnt get expanded. Its always same
It receives a modem_message, so the event works - thats tested and is not the Problem. Also i know that #Clients can return the table length too but i have a good reason why i did it not that way (#tbl only works for numerical keys)
What am i doing wrong?
//EDIT: the reduced code works... mmh why not the real?
Link to post
Share on other sites