162 posts
Posted 24 February 2014 - 12:07 PM
I'm bad with coding and I'm making an API program so when making new programs on a server and stuff, things I do a lot will be just a function rather than a bunch of lines ex:
term.clear()
term.setCursorPos(1,1)
-- etc
Here's my program so far,
function reset()
term.clear()
term.setCursorPos(1,1)
if term.isColor() then
term.setTextColor(colors.white)
term.setBackgroundColor(colors.black)
end
end
Here's the program I'm testing it with
os.unloadAPI("appleAPI")
os.loadAPI("appleAPI")
reset()
When I run the test program I get attempt to call nil but as far as I know, the function "reset()" should be a real function so I'm confused.
91 posts
Posted 24 February 2014 - 12:13 PM
If your API file is apple then you would need to use
apple.function()
162 posts
Posted 24 February 2014 - 12:16 PM
If your API file is apple then you would need to use
apple.function()
That actually makes sense, thanks!
EDIT: Attempt to index ? (a nil value) when I ran my test program.
SECOND EDIT: My 100th post! Wow.
Edited on 24 February 2014 - 11:18 AM
162 posts
Posted 24 February 2014 - 12:29 PM
ignore that last post. I literally did apple.reset() instead of appleapi… The stupidity is strong here,
882 posts
Location
Behind you.
Posted 24 February 2014 - 03:41 PM
Nice job on 100 posts. I recently got my 256th. c:
And good luck on your API
I think people use 'term.isColor and term.isColor()' instead of just 'term.isColor()', so I would suggest putting that in :P/>
162 posts
Posted 24 February 2014 - 03:57 PM
Nice job on 100 posts. I recently got my 256th. c:
And good luck on your API
I think people use 'term.isColor and term.isColor()' instead of just 'term.isColor()', so I would suggest putting that in :P/>
Okay, but quick question, I'm a code noob so I could be wrong, but doesn't typing it without the parenthesis just check if it's defined? I kinda don't see the point in doing both.
758 posts
Location
Budapest, Hungary
Posted 24 February 2014 - 04:36 PM
doing both
That will first check if there actually is a
term.isColor function, and calls it only then. That's important if your program is compatible with the older versions of ComputerCraft (such as 1.33). Lua won't check the second part of the
and expression if the first part evaluated false, since in the end the expression will evaluate false anyway because of the and keyword (yeah, Lua is
that awesome). We can use that awesomeness to avoid calling the potentially non-existent
term.isColor, and call it only if it actually exists.
7083 posts
Location
Tasmania (AU)
Posted 24 February 2014 - 05:05 PM
Note that "term.clear()" sets the whole display to what the current background colour is. You probably want to ensure the background colour is black before clearing.
Also note that non-colour displays can still set the background colour to white, and the text colour to black (and back again).