24 posts
Posted 11 May 2012 - 04:21 PM
ok now so i started editing monitor script
and added:
if txt ~= "/position" then
local x = read()
m.SetCursorPos(x)
end
and when i type /position and set it
and try to send message it says that monitor needs number,number
any help?
14 posts
Posted 11 May 2012 - 04:56 PM
ok now so i started editing monitor script
and added:
if txt ~= "/position" then
local x = read()
m.SetCursorPos(x)
end
and when i type /position and set it
and try to send message it says that monitor needs number,number
any help?
if txt ~= "/position" then
local x = read()
m.setCursorPos(1,1)
end
Got rid of two problems there.
~Set, cannot be capitalized
~CursorPos(x,x) need a location, not (x)
24 posts
Posted 11 May 2012 - 07:55 PM
i want if i type /position that i can type position iwant
instead of editing program all time :)/>/>
14 posts
Posted 11 May 2012 - 08:19 PM
ah, well im still pretty new to lua… so im not sure what to do… hmm
1604 posts
Posted 11 May 2012 - 08:25 PM
Is something like this what you want?
if txt == "/position" then
write("x: ")
local x = tonumber(read())
write("y: ")
local y = tonumber(read())
m.setCursorPos(x, y)
end
It would ask for the x and y position and change the monitor position to that. You may want to check if the entered values are numbers though (check if x and y are nil).
24 posts
Posted 12 May 2012 - 07:41 AM
Spoiler
local function open() –this function detects any monitor
local bOpen, sFreeSide = false, nil
for n,sSide in pairs(rs.getSides()) do
if peripheral.getType( sSide ) == "monitor" then
return sSide
end
end
return false
end – end of the function
x = open() – this checks if the function said that a monitor is given
if x == false then
print("please add a monitor") – end of the check
else
local m = peripheral.wrap(x) – this adds the monitor
m.clear()
m.setCursorPos(1,1)
m.write("Welcome to Our Internet Cafee Club")
m.setCursorPos(1,2)
m.write("Please, reboot Computer after every use")
m.setCursorPos(1,3)
m.write("If You struggle to turn off any of Our games, hold down /CTRL/ + /T/")
m.setCursorPos(1,4)
m.write("and it will auto terminate!")
m.setCursorPos(1,9)
m.write("Thanks for trying our applications!, We hope that you will have fun!")
m.setCursorPos(1,6)
m.write("If You want to buy any of our games, ask our workers to burn it to")
m.setCursorPos(1,7)
m.write("blank floppy disk, CHARGES MAY APPLY!")
end
thx for help but i already did this
but got another problem.
how to detect redstone input and activates shutdown as long as red output is on? (like maintemance time)
–edit
if you can give me easy instructions to learn lua easilly i wolud apprichiate it!
(i am bat at english, i think i spelled it out wrong)
8543 posts
Posted 12 May 2012 - 04:43 PM
You'll have to detect incoming redstone events using os.pullEvent(), or perhaps filter for just redstone events with os.pullEvent("redstone").
24 posts
Posted 12 May 2012 - 07:39 PM
so this sholud look like this?
os.pullEvent("redstone")
if redstone.getOutPut == false then
print("MAintemance time¨!")
os.shutdown()
else
print("PC UP and working!")
end
474 posts
Posted 12 May 2012 - 08:25 PM
so this sholud look like this?
os.pullEvent("redstone")
if redstone.getOutPut == false then
print("MAintemance time¨!")
os.shutdown()
else
print("PC UP and working!")
end
Nope, it should something like:
while true do
local e, s = os.pullEvent()
if e == "redstone" then
print("Maintenance time, got redstone input from "..s.." side!")
sleep(2)
os.shutdown()
else
print("PC up and working!")
break
end
end
1604 posts
Posted 12 May 2012 - 08:33 PM
so this sholud look like this?
os.pullEvent("redstone")
if redstone.getOutPut == false then
print("MAintemance time¨!")
os.shutdown()
else
print("PC UP and working!")
end
Nope, it should something like:
while true do
local e, s = os.pullEvent()
if e == "redstone" then
print("Maintenance time, got redstone input from "..s.." side!")
sleep(2)
os.shutdown()
else
print("PC up and working!")
break
end
end
The redstone event has no arguments, so you should check for the side you want with rs.getInput().
If you just need to check at startup if the input is on, just do:
if rs.getInput("side") then -- change "side" to the side you want to check
print("Maintenance time, shutting down...")
sleep(1)
os.shutdown()
end
If you need to check during the program:
while true do
local evt, arg = os.pullEvent()
if evt == "redstone" then
if rs.getInput("side") then -- change "side" to the side you want to check
print("Maintenance time, shuting down...")
sleep(1)
os.shutdown()
end
elseif evt == "..." then -- check other events here
...
end
end
24 posts
Posted 12 May 2012 - 09:04 PM
i want to check it every 60sec, without interupting orther programs :P/>/>
8543 posts
Posted 12 May 2012 - 11:07 PM
That would probably be something you'd want to use the parallel API for. Check out the ComputerCraft wiki's API page.