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

How to create an OS with ComputerCraft?

Started by RitmoS, 29 November 2013 - 01:22 PM
RitmoS #1
Posted 29 November 2013 - 02:22 PM
I want to know, how to create an operating system with ComputerCraft because there are not many tutorials on the internet …

I wanted some code for beginners. Example: how to create buttons, create applications, create backgrounds for the program, etc …

Will someone help me?

Grateful,
RitmoS
Edited on 29 November 2013 - 08:54 PM
Zudo #2
Posted 29 November 2013 - 03:52 PM
You will need to use os.pullEvent() to detect mouse clicks. What do you mean by funds?
Edited on 29 November 2013 - 02:54 PM
H4X0RZ #3
Posted 29 November 2013 - 04:07 PM
Okay, a dirty tutorial to buttons:
SpoilerOlay, you want to use buttons. Follow this dirty tutorial to understand the basics:

We'll need a new table (for example called buttons):

buttons = {}

So, when we got the table, we write a function to add a button next:

local function setBtn(x,y,xt)
--# x,y is the position
--# txt is the text 
table.insert(buttons,{x,y,txt}
--# We add a new table which the button informstions to the buttons table
end

When we have that, we need another function to draw the buttons:

local function drawBtn()
--# no need for arguments
term.setBackgroundColor(colors.white)
term.setTextColor(colors.black)
--# you can change to color if you want
for k,v in pairs(buttons) do
--# looping through the buttons table
term.setCursorPos(v.x,v.y)
--# going to the buttons position
term.write(v.txt)
--# draw the button's text
end
end

and a function to chek if a button got clicked


local function checkClick(x,y)
--# x,y the position where you click
for k,v in pairs(buttons) do
--# looping through the buttons
if x >= v.x and y == v.y and x <= v.x+v.txt.length() then
--# check if the poition fits to a button
return k
--# return the button id
break 
--# stop the loop
end
end

Then you use it like this in the main loop:

setBtn(3,4,"test") -- id is 1
while true do
local _,btn,x,y = os.pullEvent()
drawBtn()
if _ == "mouse_click" then
if checkClick(x,y) == 1 then
print("button 1 got clicked")
end
end
sleep(0)
end

I hope you understood it!

Greetings,
Freack100
Engineer #4
Posted 29 November 2013 - 04:14 PM
You will need to use os.pullEvent() to detect mouse clicks. What do you mean by funds?
… Frankly, I have no words for this

Anyway, here is a tutorial how to use events. And here is a more specific tutorial for button

Applications are just some icon-button which launches most of the with the shell.run, but you really should get into file reading and running those via pcall and all those fancy stuff.

Here is a tutorial for file reading and with that content you can use loadstring* and pcall

Those should get you at least started ;p

* This is explains it just roughly, google is your friend I suppose!
Edited on 29 November 2013 - 03:45 PM
ElvishJerricco #5
Posted 29 November 2013 - 04:19 PM
If you have to ask how to build an OS, you're not ready to build an OS. Start with simpler programs.

Also: People, buttons are not the fundamental feature of an OS -_-/>
Engineer #6
Posted 29 November 2013 - 04:27 PM
If you have to ask how to build an OS, you're not ready to build an OS. Start with simpler programs.

Also: People, buttons are not the fundamental feature of an OS -_-/>/>
He asked for it
oeed #7
Posted 29 November 2013 - 05:23 PM
One of the best ways would be to take a look at other people OSs. I can think of a few OSs that would be good for learning from. If you want to get a user interface then VoidOS or KREOS might be good starting points. If you're wanting something with programs running in windows (shell programs) then I'd look at Cannon OS, you could also look at LyqydOS but I've found that the code is incredibly hard to read.

My biggest recommendation is, however, to make a drawing engine. I've made one and it makes everything so much quicker and easier to do. I also means that you can have a buffer. I see tons of OSs which draw everything manually using 'term.write' and it just doesn't allow for much flexibility.

You can find (a rather old version) my drawing engine here as an example.
RitmoS #8
Posted 29 November 2013 - 09:53 PM
Thanks for ZudoHackz, Freack100, Engineer and mainly oeed, that helped me a lot, with only an answer.

Now it's so easy to create an OS…
I'll go create an operating system as of now. (I hope…)

Thanks for all,
RitmoS

P.S.: Admin, please, doesn't block this topic… Others users can ask here too, including me.

I've a doubt:

How to add background in the OS?
Exemple: The logo of my system with a loading bar.

Thanks,
RitmoS