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

Creating a GUI in ComputerCraft - Attempt to call nil

Started by Beatsleigher, 21 December 2013 - 02:57 PM
Beatsleigher #1
Posted 21 December 2013 - 03:57 PM
Heyo there,

I've recently found the awesome email client/server by NitrogenFingers and got myself a copy and modified it to my needs (Of course by keeping his name in it).

Now I've extended the range of wireless modems from 50 to 10000000 (Simply so it'll work over most of the server) and to make this easy for users to use, I wanted to create a GUI installer.

I've used Lua to code basic things and a login system (Thanks to the person who helped me there!) but for whatever reason, when I attempt to use functions myself, I always get an error: Attempt to call nil.

Here's the code so far:

-- CreepyBeast Tekkit Email Client Installer
-- Vars
selection = 0
-- End vars
print("Welcome to the CreepyBeast Tekkit Email Client Installer")
print("This installer will set following up for you:")
print("1. Email Client and Rednet port setup.")
print("2. Redstone output when computer is running.")
print("3. Boot settings")
print("")
print("Hit ENTER to continue with setup...")
read()
drawInterface()
-- Draw Interface --
function drawInterface()
term.clear()
term.setCursorPos(1, 1)
printHeader()
printCentered(4, "SELECT INSTALLATION TYPE:")
printCentered(6, "BASIC INSTALLER (Recommended)")
printCentered(8, "ADVANCED INSTALLER")
end
function printHeader()
term.clear()
term.setCursorPos(1, 1)
print("CREEPYBEAST TEKKIT EMAIL CLIENT INSTALLATION")
printRight(1, "v0.1")
end
function printRight(height, value)
  local xpos = w - string.len(value)
  term.setCursorPos(xpos, height)
  term.write(value)
end
function printCentered(height, value)
  local xpos = w/2 - string.len(value)/2
  term.setCursorPos(xpos, height) 
  term.write(value)
end
-- I nicked the printRight and printCentered functions from the email client

As soon as I execute the program I get:


I'm a Java and C# developer, I've written my own installers, programs and libs in both languages, plus VB.Net but Lua is still confusing me. :(/>

Thanks for your help.
Lyqyd #2
Posted 21 December 2013 - 05:15 PM
Declare your functions before you call them.
Sora Firestorm #3
Posted 21 December 2013 - 05:27 PM
To expand on what Lyqyd said, you need to be sure that any function that you've written is declared (written out) before you call it, because Lua reads top to bottom.
Beatsleigher #4
Posted 21 December 2013 - 11:53 PM
Thanks, you guys.
That's actually pretty annoying. Lol
Well, I'll make do :)/>