Jump to content




Simple startup script for non programers

lua peripheral api

5 replies to this topic

#1 neluxjanz

  • New Members
  • 2 posts

Posted 28 June 2015 - 12:05 PM

--#####################user variables########################
local w,h =  term.getSize()
local wm, hm, monitor
local machine = "back"
local lights = "right"
local Monitor = "top"
local Modem = "left"
local password = "necas"
local opentime = 120
local systime = 2
local title = "Welcome NeluxOS"
local iniText = "Iniciating system test"
local lightsText = "Lights on?"
local lightsOtext = "Lights stay off"
local passwordText = "Password:"
local passwordCtext = "Password correct!"
local passwordItext = "Password incorrect!"
local factoryWtext = "Factory is working..."
local factoryStext = "Factory has stop"
--##############get monitor##############
function startMonitor()
  peripheral.call(Monitor, "write", "Test")
  monitor = peripheral.wrap(Monitor)
  wm, hm = monitor.getSize()
end
--#####clear both shell and monitor#####
function clearScreen()
term.clear()
term.setBackgroundColor(colors.black)
term.setTextColor(colors.green)
monitor.clear()
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.green)
monitor.setTextScale(.5)
end
--###keep first line and clear all rest###
function cleanline()
monitor.clearLine(2,x)
term.clearLine(2,x)
end
--###########tittle position#########
function screenTpos()
term.setCursorPos(1,1)
monitor.setCursorPos(1,1)
end
--#########content position########
function screenGpos()
term.setCursorPos(1,2)
monitor.setCursorPos(1,2)
end
--#####start modem - "under test"####
function startModem()
modem = peripheral.wrap(Modem)
modem.open(0)
modem.isOpen(0)
--modem.closeAll()
end
--#### X function echo's to all present devices ###
x = function()
print(t)
monitor.write(t,wm)
modem.transmit(0,1,t)
end
--######initiating peripherals#####
startMonitor()
startModem()
--####gets X/Y and the routine aware of changes in resolution###
for k,v in pairs(peripheral.getMethods(Monitor)) do
print(v)
print("Terminal size = " .. w .. "," .. h)
print("Monitor size = " .. wm .. "," .. hm)
end
--########LOGIC TiME#######
clearScreen()
screenTpos()
t = title
x()
sleep(systime)
screenGpos()
t = iniText
x()
sleep(systime)
sleep(4)
cleanline()
while true do
screenGpos()
t = lightsText
x()
local input = read()
if input == "yes" then
cleanline()
screenGpos()
rs.setOutput(lights,true)
else
cleanline()
  screenGpos()
t = lightsOtext
x()
end
cleanline()
screenGpos()
t = passwordText
x()
local input = read("*")
if input == password then
cleanline()
screenGpos()
t =  passwordCtext
x()
  sleep(systime)
  rs.setOutput(machine,true)
cleanline()
  screenGpos()
t = factoryWtext
x()
  sleep(opentime)
  screenGpos()
  rs.setOutput(machine,false)
t = factoryStext
x()
cleanline()
  screenGpos()
else
t = passwordItext
x()
sleep(2)
os.shutdown()
--shell.run(boolean)
clearScreen()
screenTpos()
end
end

Edited by neluxjanz, 10 July 2015 - 01:15 PM.


#2 CompuTech

  • Members
  • 262 posts
  • LocationBoston, MA

Posted 28 June 2015 - 05:29 PM

Use code tags. It'll make your forum post look much neater

#3 98Games_YT

  • Members
  • 42 posts
  • LocationEarth

Posted 30 June 2015 - 09:03 PM

If you want people to use your code, try putting it on Pastebin. ComputerCraft comes with a Pastebin program that you can use to upload programs and download programs. Using Pastebin with your code will make it much easier for people to use.

EDIT: I put it on pastebin for you to save the trouble

To get the code, type in on CraftOS 'pastebin get GUX9021V startup'
or for the source code, type this URL into your web browser: http://pastebin.com/GUX9021V

Hope I helped you today :)

Edited by MCFunRide, 30 June 2015 - 09:05 PM.


#4 cyanisaac

  • Members
  • 369 posts
  • LocationSan Diego, CA

Posted 03 July 2015 - 02:39 AM

I'm... not really sure this is an OS. It doesn't appear to sandbox anything or run around any apps, this appears to be a startup program, in which case it should go in programs.

It's also extremely hard to run, you need a monitor AND a modem and if you don't have that then it will crash, and even then I get some "password incorrect" bug that I don't know how to work around, is there even a password?

Can you maybe explain a bit about what this does and how to set it up? That would help greatly.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 03 July 2015 - 03:41 AM

View Postcyanisaac, on 03 July 2015 - 02:39 AM, said:

I'm... not really sure this is an OS. It doesn't appear to sandbox anything or run around any apps, this appears to be a startup program, in which case it should go in programs.

That's not the classification criteria. This is the correct location for this program, as far as I can tell.

#6 neluxjanz

  • New Members
  • 2 posts

Posted 10 July 2015 - 11:53 AM

My friends of course its not a OS, I just put that name to test the refresh rate while the function clearline() and screenGpos() and see if I the monitor buffer holds. Also thanks for the heads up on the code tags. :wacko:/>

View PostMCFunRide, on 30 June 2015 - 09:03 PM, said:

If you want people to use your code, try putting it on Pastebin. ComputerCraft comes with a Pastebin program that you can use to upload programs and download programs. Using Pastebin with your code will make it much easier for people to use.

EDIT: I put it on pastebin for you to save the trouble

To get the code, type in on CraftOS 'pastebin get GUX9021V startup'
or for the source code, type this URL into your web browser: http://pastebin.com/GUX9021V

Hope I helped you today :)/>

Thanks for tip ,this is a quite useful tool :)/> , just started to play minecraft a few weeks ago, and when I've learn about computerCraft I just loved it... :lol:/>
I've commented the code, and put the code tags on .
Also have to point out that the variables are setup to the world I have in minecraft.

I hope with the comments help. ;)/>

View PostLyqyd, on 03 July 2015 - 03:41 AM, said:

View Postcyanisaac, on 03 July 2015 - 02:39 AM, said:

I'm... not really sure this is an OS. It doesn't appear to sandbox anything or run around any apps, this appears to be a startup program, in which case it should go in programs.

That's not the classification criteria. This is the correct location for this program, as far as I can tell.


We can argue that it is current form does not resemble a operating system but it takes a good bit of Lua from the user ,meaning all sides of the cube are supported and extra peripherals.
I gave'it the name startup so it starts on boot and the user only has to do one conf.

Thank you for all the reply's and sorry for time it toke to respond...(stuff) :(/>

Edited by neluxjanz, 10 July 2015 - 04:19 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users