local rooms = {true, true, true, true} --true = unoccupied, false = occupied; all rooms start off occupied rednet.open("top") monitor = peripheral.wrap("right") monitor.setTextScale(2.5) term.redirect(monitor) function listen() --waits for rednet input, then writes to "rooms" table while true do id, mes = rednet.receive(nil) local room = string.sub(mes,1,-2) local open = tonumber(string.sub(mes,-1,-1)) write("Room " .. room .. " is now ") --Debug check if open > 0 then print("open!") rooms[room] = true else print("closed!") --This does, in fact, print rooms[room] = false end print("The value at index " .. room .. " is now " .. tostring(rooms[room])) --Sanity check: it does print false sleep(5) --Shouldn't get messages too frequently end end function display() --Reads table, displays on monitor while true do term.setBackgroundColor(colors.black) term.clear() term.setCursorPos(1,1) for i=1,#rooms do print("The value at index " .. i .. " is " .. tostring(rooms[i])) --Sanity check: always prints true! term.setBackgroundColor(colors.black) term.setTextColor(colors.white) write("Room " .. i .. ": ") --Actual display if rooms[i] then term.setBackgroundColor(colors.green) --Always gets printed, even after claiming to have closed the room term.write("Empty") else term.setBackgroundColor(colors.red) term.write("Taken") end term.setBackgroundColor(colors.black) print(" (" .. tostring(rooms[i]) .. ")") --Final sanity check: also always prints true! end sleep(10) --Will be decreased, but currently high for debugging purposes end end parallel.waitForAll(listen, display)
Even after it receives a rednet signal that one room has closed, it continues to show "open" and "true". Here are pictures to demonstrate:
Upon startup
Right after closing one room (display hasn't updated the screen yet)
After display() updates the screen again
Is this a problem with the parallel API itself, or am I just doing something wrong?