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

LUA HELP

Started by Falco, 25 December 2012 - 07:30 PM
Falco #1
Posted 25 December 2012 - 08:30 PM
I'm stuck on this peice of code I'm trying to use to print test onto a monitor like alerts and so forth.


But so far i have this and even this dont work :(/> ……


function testprint
    print("TesTING!...1...2...3...")
end

shell.run("monitor", "right", testprint)
 
Sammich Lord #2
Posted 25 December 2012 - 09:15 PM
There are two ways of declaring functions:

functionName = function()
  print("Codez")
end

functionName()
  print("Codez")
end
Falco #3
Posted 25 December 2012 - 09:17 PM
omg im derped lool i forgot the () thanks man :)/>
Sammich Lord #4
Posted 25 December 2012 - 09:24 PM
omg im derped lool i forgot the () thanks man :)/>
We all make mistakes. :P/>
remiX #5
Posted 26 December 2012 - 01:40 AM

functionName()
  print("Codez")
end

Isn't it
function functionName()
  print("Codez")
end
Falco #6
Posted 26 December 2012 - 02:28 AM
I cant seem to work out how to print text to a monitor…. please help…..
remiX #7
Posted 26 December 2012 - 03:35 AM
Ok, well printing on monitors is nearly as easy as computer terminals, the main thing you need to do,
is wrap the monitor with peripheral.wrap("side") where "side" is the side on which the monitor is.


s_monitorSide = "left" -- The side in which the monitor sits in respect of the computer
monitor = peripheral.wrap(s_monitorSide)
if not monitor then
    print("Monitor is not on the " .. s_monitorSide .. " side.\nSearching for one automatically.")
    for i, side in pairs(rs.getSides())                    -- This will automatically search
        if peripheral.getType(side) == "monitor" then    -- for a monitor on all available
            s_monitorSide = side                        -- sides
            break
        end
    end
    return -- If no monitor is found, it will then return to shell.
end

--[[
    Now in order to make printing easier, we make a function to print,
    because you can only write to the monitor, which does not go
    to the next line automatically.
--]]

function monPrint(text)
    cX, cY = monitor.getCursorPos()
    monitor.write(text) -- This will write the text to the monitor
    monitor.setCursorPos(cX, cY+1) -- This will change the cursor to the next line
end

monPrint("Hello!")
monPrint("This text is being printed on the monitor on the " .. s_monitorSide)
monPrint("This should be the 3rd line if the monitor is big")