695 posts
Location
In my basement.
Posted 14 June 2013 - 06:30 AM
Hi! I've had this project going on for a little while now..
My first API.
Download in-game: pastebin get VXCPhReN MackCode
Load it in your program with:
os.loadAPI("MackCode")
Functions:
MackCode.cls() this will clear the screen.
MackCode.txtCol(col) this will set the text color to "col"
MackCode.bgCol(col) same as above but background
MackCode.bgcolc(col) same as bgCol but will also clear the screen.
MackCode.getVer() Prints the version
MackCode.saveFile(filename, mode, text) will open the file "filename" in mode "mode" and write "text".
MackCode.del(filename) will delete "filename"
MackCode.size() Gets the size of screen in w, h
MackCode.cursor(x, y) sets the cursor position to x, y
MackCode.centerPrint(string, x, y) prints the string in the center of screen on y level. For best results make x 2
Leave what you think and suggestions and stuff below.
Thanks // Mackan90096
1688 posts
Location
'MURICA
Posted 14 June 2013 - 08:35 AM
This is pretty pointless. A lot of these functions are just wrappers, or simplify very easy processes. Your centerPrint() function won't work, because it tries to use the string API while having "string" as a variable, and your size() function shouldn't set global variables, as not everyone uses w and h for screen size. Lastly, this is mostly my opinion, but I don't think "easter egg" functions belong in APIs.
7508 posts
Location
Australia
Posted 14 June 2013 - 08:42 AM
and the "easter egg" is recursive so would crash after some time too.
EDIT:Also what is the point of supplying an X for a
centre print function?
a better centre print:
function centerWrite( msg, y )
local sw, sh = term.getSize()
term.setCursorPos( math.floor( ( sw - #msg ) / 2 ) + ( #msg % 2 == 0 and 1 or 0 ), y or sh / 2 )
write( msg )
end
function centerPrint( msg, y )
centerWrite( msg..'\n', y )
end
Edited on 14 June 2013 - 06:45 AM
1688 posts
Location
'MURICA
Posted 14 June 2013 - 08:56 AM
The math there is a bit complicated. Using math.ceil rather than adding 1 if the length of the string is positive is much simpler.
function centerWrite( msg, y )
local sw, sh = term.getSize()
term.setCursorPos( math.ceil( ( sw - #msg ) / 2 ), y or sh / 2 )
write( msg )
end
7508 posts
Location
Australia
Posted 14 June 2013 - 09:01 AM
The math there is a bit complicated. Using math.ceil rather than adding 1 if the length of the string is positive is much simpler.
I remember
math.ceil didn't work in 1 particular case, can't remember what it was now, but I remember I picked the +%2 for a reason.
587 posts
Location
Wrocław, Poland
Posted 14 June 2013 - 12:20 PM
Instead of math.ceil do
local function ceil(n)
return n - n%1
end
Broken with n < 0 tho…
808 posts
Posted 14 June 2013 - 01:22 PM
Instead of math.ceil do
local function ceil(n)
return n - n%1
end
Broken with n < 0 tho…
What's the difference between this and math.floor?
587 posts
Location
Wrocław, Poland
Posted 14 June 2013 - 02:43 PM
IDK, ask TOBIT. He says that math.ceil is broken… :P/>
695 posts
Location
In my basement.
Posted 14 June 2013 - 04:09 PM
… I'm confused now…
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 14 June 2013 - 04:23 PM
I do agree that this API is semi-useless. There are some functions that are shortcuts, but they're mostly copies of the term API. I say, if you want to make an API everyone will love, work on making shortcuts for commonly used and long things.
587 posts
Location
Wrocław, Poland
Posted 15 June 2013 - 12:32 AM
Agreed :P/>
808 posts
Posted 15 June 2013 - 02:22 AM
IDK, ask TOBIT. He says that math.ceil is broken… :P/>/>
Math.ceil isn't broken. Like most floating point math operations, there's one specific number that doesn't work with math.ceil. And you didn't write a working ceil function. You wrote a working floor function, which is exactly the opposite. Also it doesn't break when you go to negatives, it works just as standard math.floor works.
587 posts
Location
Wrocław, Poland
Posted 15 June 2013 - 12:44 PM
Herp derp true :P/>
local function ceil(n)
return n+1-n%1
end
It's ceil now ^_^/>
42 posts
Location
In a galaxy far far away, aka New York
Posted 16 June 2013 - 09:36 PM
Most of these functions already exist in the term API
467 posts
Location
Van Diemen's Land
Posted 20 June 2013 - 02:19 AM
Most of these functions already exist in the term API
^What he said. At least I have functions that do not exist in any other default API in QuickTils. :P/>