Jump to content




Creating a GUI in ComputerCraft - Attempt to call nil


  • You cannot reply to this topic
3 replies to this topic

#1 Beatsleigher

  • Members
  • 37 posts
  • LocationGermany, Osnabrueck

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:
Posted Image

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.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 21 December 2013 - 05:15 PM

Declare your functions before you call them.

#3 Sora Firestorm

  • Members
  • 89 posts

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.

#4 Beatsleigher

  • Members
  • 37 posts
  • LocationGermany, Osnabrueck

Posted 21 December 2013 - 11:53 PM

Thanks, you guys.
That's actually pretty annoying. Lol
Well, I'll make do :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users