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

Help me! Function buGS

Started by thegreatstudio, 04 May 2013 - 07:29 AM
thegreatstudio #1
Posted 04 May 2013 - 09:29 AM

function draw()
desktop = paintutils.loadImage("background")
paintutils.drawImage(image, screenX, 3)
end
local screenX, screenY = term.getSize()
term.clear()
term.setCursorPos(1, 1)
os.sleep(1)
while true do
term.setBackgroundColor(colors.cyan)
term.clear()
paintutils.drawLine(1, 1, screenX, 1, colors.lightGray)
term.setTextColor(colors.black)
term.setCursorPos(1, 2)
term.setBackgroundColor(colors.lightBlue)
term.setTextColor(colors.blue)
print("[Studio]")
term.setBackgroundColor(colors.red)
term.setCursorPos(10, 2)
term.setTextColor(colors.lightBlue)
print(" [Programs] ")
term.setCursorPos(30 , 1)
term.setTextColor(colors.black)
term.setBackgroundColor(colors.lightGray)
print("Testing 2")
while true do
local event, button, X, Y = os.pullEvent("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 2 and button == 1 then
print("Welcome to Studio OS")
sleep(1)
studio() -- Error: attempt to call nil
elseif X >= 10 and X <= 20 and Y == 2 and button == 1 then
print("Welcome to program section!")
sleep(1)
program() -- Error:attempt to call nil
end
end
end
end
function studio()
term.clear()
term.setBackgroundColor(colors.cyan)
term.clear()
paintutils.drawLine(1, 1, screenX, 1, colors.lightGray)
term.setTextColor(colors.black)
term.setCursorPos(1, 2)
print("[Terminal]")
local event, button, X, Y = os.pullEvent("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 2 and button == 1 then
term.clear()
print("Studio OS version. Testing 3")
print("Type /help for commands!")
while true do
cmd = read("> ")
if cmd == "/help" then
print("Coming soon")
end
end
end
end
end
function program()
term.clear()
term.setBackgroundColor(colors.cyan)
term.clear()
paintutils.drawLine(1, 1, screenX, 1, colors.lightGray)
term.setTextColor(colors.white)
term.setCursorPos(1, 2)
term.setBackgroundColor(colors.black)
print("[Terminal]")
local event, button, X, Y = os.pullEvent("mouse_click")
if event == "mouse_click" then
if X >= 1 and X <= 10 and Y == 2 and button == 1 then
term.clear()
term.setCursorPos(1, 1)
print("Studio OS Testing 2")
print("Type exit to exit this program.")
print("Type help to get started!")
while true do
cmd = read("# ")
if cmd == "help" then
print("Shutdown -- Shutsdown the computer")
print("Restart -- Restarts the computer")
print("Edit -- edits a file")
print("paint -- paints the program!")
print("clrs -- clears the screen")
elseif cmd == "shutdown" then
os.shutdown()
elseif cmd == "restart" then
os.restart()
elseif cmd == "exit" then
break
elseif cmd == "clrs" then
term.clear()
term.setCursorPos(1, 1)
print("Studio OS Testing 2")
print("Type exit to exit this program.")
print("Type help to get started!")
else
shell.run(sr)
end
end
end
end
end

Help me please!
Engineer #2
Posted 04 May 2013 - 09:57 AM
What is the unexpected behaviour/error you get?… You should know that by now..
thegreatstudio #3
Posted 04 May 2013 - 10:06 AM
the error is attempt to call nil
GravityScore #4
Posted 04 May 2013 - 11:32 AM
You put the program function below where you're calling it from. Move it to the top of the file and it should work.

As a general rule, any functions you call must be placed above where you're calling them from.
thegreatstudio #5
Posted 04 May 2013 - 12:44 PM
You put the program function below where you're calling it from. Move it to the top of the file and it should work.

As a general rule, any functions you call must be placed above where you're calling them from.

ok i'll try it
Dlcruz129 #6
Posted 05 May 2013 - 02:24 AM
Argh. Indent your code, mine eyes are bleeding.