I read the wiki on functions here: http://computercraft.../Function_(type)
From what I understand, It states that functions are seen as variables. This means it would just re-write myFunction() to the latter one if two or more statements exist declaring this function (appears to do this with minor testing, unless I just did something wrong).
I was wondering if there was something I missed that handles a feature like this (similar to constructors in java) if I needed to have multiple functions with the same name that accept different amounts of variables, and could someone link me to or give an example if it exists?
Example of what I am talking about:
-- I want it to choose which of these to run based on the number of variables passed to it.
-- Version 1:
function mWrite(monitor, x, y, text)
monitor.setCursorPos(x,y)
monitor.write(text)
end
-- version 2: (only if tcolor variable is present)
function mWrite(mon,x,y,text,tcolor)
monitor.setCursorPos(x,y)
monitor.setTextColor(tcolor)
monitor.write(text)
Instead of having to separate them or preform checks for everything in 1 function like the following setup:
function mWrite(monitor, x, y, text, tcolor)
setCursorPos(x,y)
if tcolor then
monitor.setTextColor(tcolor)
else
monitor.setTextColor(colors.white)
end
monitor.write(text)
end
Thanks!
~xArsonisttx