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

Program Crashes on click on screen

Started by makeme, 07 March 2014 - 10:43 PM
makeme #1
Posted 07 March 2014 - 11:43 PM
I had this program working a couple of nights ago and haven't changed anything but now it crashes when I try to click on the monitor.

Full Code - TankMon - steAmPI

It says "TankMon:132: Attempt to call nil" I've checked the syntax

Heres the code:

local MonTouch = {os.pullEvent()}
if MonTouch[1] == "monitor_touch" then
   if MonTouch[3] >= X1Pos and MonTouch[3] <= X1Pos + 10 and MonTouch[4] >= Y1Pos and MonTouch[4] <= Y1Pos + 1 then
    steAmPI.OnPushData(tank1, Mon)
   elseif MonTouch[3] >= X2Pos and MonTouch[3] <= X2Pos + 10 and MonTouch[4] >= Y1Pos and MonTouch[4] <= Y1Pos + 1 then
    steAmPI.OnPushData(tank2, Mon)
   elseif MonTouch[3] >= X1Pos and MonTouch[3] <= X1Pos + 10 and MonTouch[4] >= Y2Pos and MonTouch[4] <= Y2Pos + 1 then
    steAmPI.OnPushData(tank3, Mon)
   elseif MonTouch[3] >= X2Pos and MonTouch[3] <= X2Pos + 10 and MonTouch[4] >= Y2Pos and MonTouch[4] <= Y2Pos + 1 then
    steAmPI.OnPushData(tank4, Mon)
   else
end
  else
   --skip
  end

it references

function OnPushData(FluDetails, Mon)
local FluName = FluNamePicker(FluDetails["name"])
local Amount = FluDetails["amount"]
local Cap = FluDetails["capacity"]
local Percent = Percentage(Amount, Cap)
local RPercent = Round(Percent, 2)
Mon.clear()
Mon.setCursorPos(5,2)
Mon.setTextScale(2)
Mon.setTextColor(colors.white)
Mon.write(FluName)
Mon.setTextScale(1)
Mon.setCursorPos(3,3)
Mon.write("" .. Amount .. "/" .. Cap .. "")
Mon.setCursorPos(3,4)
Mon.write("" .. RPercent .. "%")
Mon.setCursorPos(13,10)
Mon.setBackgroundColor(colors.red)
Mon.setTextColor(colors.black)
Mon.write("<Back")
Mon.setBackgroundColor(colors.black)
while true do
local MonTouch ={os.pullEvent("monitor_touch")}
if MonTouch[4] == 13 and MonTouch[3] >= 10 and MonTouch[3] <= 14 then
return – end the function
end
end
end



Thanks I apologise in advance for the quality of my code i'm new to this :P/>
CometWolf #2
Posted 07 March 2014 - 11:53 PM
The paste code, and the one you posted is not the same. If you're using the paste code, then chances are you accidentally loaded your api functions directly into the global enviroment, by running your api directly. To properly use api functions, you need to write the api name then "." and the function name. Like you've done in the posted code.
makeme #3
Posted 07 March 2014 - 11:57 PM
The paste code, and the one you posted is not the same. If you're using the paste code, then chances are you accidentally loaded your api functions directly into the global enviroment, by running your api directly. To properly use api functions, you need to write the api name then "." and the function name. Like you've done in the posted code.

Thanks I swear I checked it must have looked at the wrong pastebin link :/