Jump to content




LUA HELP

computer lua help

6 replies to this topic

#1 Falco

  • Members
  • 33 posts
  • LocationSOMEWHERE IN F*%KING MINECRAFT!!!

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)
 


#2 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 25 December 2012 - 09:15 PM

There are two ways of declaring functions:
functionName = function()
  print("Codez")
end
functionName()
  print("Codez")
end


#3 Falco

  • Members
  • 33 posts
  • LocationSOMEWHERE IN F*%KING MINECRAFT!!!

Posted 25 December 2012 - 09:17 PM

omg im derped lool i forgot the () thanks man :)

#4 Sammich Lord

    IRC Addict

  • Members
  • 1,212 posts
  • LocationThe Sammich Kingdom

Posted 25 December 2012 - 09:24 PM

 Falco, on 25 December 2012 - 09:17 PM, said:

omg im derped lool i forgot the () thanks man :)
We all make mistakes. :P

#5 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 26 December 2012 - 01:40 AM

 Sammich Lord, on 25 December 2012 - 09:15 PM, said:

functionName()
  print("Codez")
end

Isn't it
function functionName()
  print("Codez")
end


#6 Falco

  • Members
  • 33 posts
  • LocationSOMEWHERE IN F*%KING MINECRAFT!!!

Posted 26 December 2012 - 02:28 AM

I cant seem to work out how to print text to a monitor.... please help.....

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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")






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users