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

another lua problem

Started by djhackerr, 11 May 2012 - 02:21 PM
djhackerr #1
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?
Dr_Zarreh #2
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)
djhackerr #3
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 :)/>/>
Dr_Zarreh #4
Posted 11 May 2012 - 08:19 PM
ah, well im still pretty new to lua… so im not sure what to do… hmm
MysticT #5
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).
djhackerr #6
Posted 12 May 2012 - 07:41 AM
Spoilerlocal 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)
Lyqyd #7
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").
djhackerr #8
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
cant_delete_account #9
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
MysticT #10
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
djhackerr #11
Posted 12 May 2012 - 09:04 PM
i want to check it every 60sec, without interupting orther programs :P/>/>
Lyqyd #12
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.