This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
iRichard's profile picture

Unknown problem

Started by iRichard, 30 January 2014 - 10:30 AM
iRichard #1
Posted 30 January 2014 - 11:30 AM
I post a lot of problems, but here I really know nothing more of it! The code between lines 40-44 must delete the text at line 14-31. But he does not. What is wrong?
pastebin.com/cLc0JYyF
CometWolf #2
Posted 30 January 2014 - 12:14 PM
You're defining the trj objects locally in the traject function, thus they are inaccesible to the delete function.
Edited on 30 January 2014 - 11:15 AM
iRichard #3
Posted 30 January 2014 - 12:28 PM
I have also tried without local function, but this gave the same result. I just rewrite the entire code tonight or tomorrow without local function. Hope that do go to work.
CometWolf #4
Posted 30 January 2014 - 12:45 PM
i didn't say the definition of your functions was the issue, the definition of your variables within the functions is.
iRichard #5
Posted 30 January 2014 - 01:08 PM
I don't understand that.
CometWolf #6
Posted 30 January 2014 - 01:10 PM
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
Edited on 30 January 2014 - 12:11 PM
iRichard #7
Posted 30 January 2014 - 01:54 PM
Thanks, it works. My project is almost finished. Work on a train communication system, ensuring that the driver get information, it is also possible to change the destination and line. This system has similarities with ZUB 222c, this system uses the Rotterdam metro.
Edited on 30 January 2014 - 12:54 PM
surferpup #8
Posted 30 January 2014 - 02:17 PM
Cool. Nice job on your code conventions. I understood your code very well.
iRichard #9
Posted 30 January 2014 - 02:58 PM
This is not all, I have 11 computers are to make this possible. 10 of which are along the track to be able to detect where the train is. All these computer run on CraftBang to enable multitasking. And all this computer exchange information so that each computer can do its work, so everything should be well-made stable, because there is no backup server. My next project will become a controller, with it you can track monitor. Fortunately, this is not complicated. Surely with CC1.6.
Edited on 30 January 2014 - 02:08 PM