Give this a try.
local metro = "007"
local colortext = 0x000000
local colortop = 0x444444
local colorvenster = 0x666666
local Trj1,Trj2,Trj3 -- note where im defining these local variables. This allowes all the functions within this program to acess them
local function startup()
plastic.clear()
sleep(0.2)
plastic.addBox(18,18,200,9,colortop,0.7)
plastic.addBox(18,27,200,90,colorvenster,0.7)
plastic.addText(19, 19, "GCT", colortext)
plastic.addText(199, 19, "#1", colortext)
plastic.addText(19, 28, "Wagennummer: "..metro.."", colortext)
end
local function traject( Str1, Str2, Str3 )
if Str1 == "-" then
Trj1 = plastic.addText(19, 46, "Speedlimit: -", colortext) -- Snelheidslimit
else
Trj1 = plastic.addText(19, 46, "Speedlimit: "..Str1.."km/u", colortext) -- Snelheidslimit
end
if Str2 == "-" then
Trj2 = plastic.addText(19, 55, " Next track: -", colortext) -- Volgende traject
else
Trj2 = plastic.addText(19, 55, " Next track: "..Str2.."km/u", colortext) -- Volgende traject
end
if Str3 == "-" then
Trj3 = plastic.addText(19, 64, "Next station: -", colortext) -- Volgend station
else
Trj3 = plastic.addText(19, 64, "Next station: "..Str3.."", colortext) -- Volgend station
end
end
local function basis()
Trajectinfo.delete()
plastic.addBox(18,18,200,9,colortop,0.7)
plastic.addBox(18,27,200,90,colorvenster,0.7)
plastic.addText(19, 19, "GCT", colortext)
plastic.addText(199, 19, "#1", colortext)
plastic.addText(19, 28, "Metronumber: "..metro.."", colortext) -- Wagennummer
end
local function Trjdelete()
Trj1.delete()
Trj2.delete()
Trj3.delete()
end
--
print("[LOG] Startup") -- Opstarten
for _, v in pairs(rs.getSides()) do
if peripheral.getType(v) == "modem" then rednet.open(v) present = true break end
end
if fs.exists("/ocs/apis/sensor") then
os.loadAPI("ocs/apis/sensor")
end
for k,v in pairs(rs.getSides()) do
if (peripheral.getType(v) == "terminal_glasses_bridge") or (peripheral.getType(v) == "glassesbridge") then
plastic = peripheral.wrap(v)
break
elseif (peripheral.getType(v) == "sensor") and (not worldSensor) then
worldSensor = sensor.wrap(v)
if not (worldSensor.getSensorName() == "worldCard") then
worldSensor = false
end
end
end
local Basis = startup()
local Trajectinfo = startup()
print("[LOG] Startup sucsesfull") -- Opstarten sucsesvol
while true do
print("[LOG] Waiting for sensor") -- Wachten op sensor
local senderId, message, distance = rednet.receive()
print("[LOG] Message receive") -- Bericht ontvangen
if message == "1" then
traject("60","60", "Tussenwater")
end
if message == "2" then
Trjdelete()
end
if message == "3" then
local Trajectinfo = traject("60","60", "Tussenwater")
end
if message == "4" then
local Trajectinfo = traject("60","-", "-")
end
if message == "5" then
local Trajectinfo = traject("60","60", "Tussenwater")
end
if message == "6" then
rednet.send(88, "snelheid")
local senderId, b002, distance = rednet.receive()
print("[LOG] Speed receive: "..b002.."") -- Snelheid ontvangen
local Trajectinfo = traject("60",b002, "Tussenwater")
end
end