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:
local component = require("component")
local event = require("event")
local wlan = component.modem
local wlanPort = 7331
wlan.open(wlanPort)
local Clients = {}
function tableLength(T)
local count = 0
for k,v in pairs(T) do count = count + 1 end
return count
end
function addClient(remoteAddress)
local rcount = (tableLength(Clients) + 1)
Clients[rcount] = remoteAddress
print("Added new Client #"..rcount)
end
function messageReceived(event, localAddress, remoteAddress, port, senderDistance, message)
addClient(remoteAddress)
end
event.listen("modem_message", messageReceived)
while true do
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