--[[
tRunning = {{name}, {window}, {thread}}
]]
local thread = {
tRunning = {{},{},{}},
create = function( self, name, func )
table.insert(tRunning[1], name)
table.insert(tRunning[2], window.create(term.current(), 1, 1, 51, 19, false))
if func then
table.insert(tRunning[3], coroutine.create(func))
else
table.insert(tRunning[3], false)
end
return true
end,
resume = function( self, name )
for k, v in ipairs(tRunning[1]) do
if v == name then
if sCurrent then
for k1, v1 in ipairs(tRunning[1]) do
if v1 == sCurrent then
tRunning[2][k1].setVisible(false)
end
end
end
sCurrent = name
tRunning[2][k].setVisible(true)
term.redirect(tRunning[2][k])
if tRunning[3][k] then
coroutine.resume(tRunning[3][k])
end
end
end
end,
list = function( self )
return tRunning
end,
kill = function( self, name )
for k,v in ipairs(tRunning[1]) do
if k == name then
table.remove(tRunning[1][k])
table.remove(tRunning[2][k])
table.remove(tRunning[3][k])
end
end
end,
status = function( self, name )
for k,v in ipairs(tRunning[1]) do
if k == name then
end
end
end,
run = function( self )
end,
}
and I want it so I can do: thread:create(function)
then that adds that to the list of functions, then I can do like: thread:run() and it will run them all, now this is the part I am not sure on, how do I switch to an app? and then direct all the arguments that are given to that?
So I want to be able to make a function that holds the information for each screen and all the content so say (my app store) the menu function is here:
functiom menu()
-- menu code
end
and I have the upload app function:
function upload()
-- do upload function here
end
Every function has a os.pullEvent() that allows you to interact with the screen so how could I use the above to switch between them? so the code above (top) comes with a name, window and coroutine, so how would I go about making it so when I run a new task it creates the coroutine and runs it, loading all the screen information etc, then when I click on say the top menu bar to go to another app it then will thread:resume("menu") and then load the window for that and then run that, still keeping in mind that the os.pullEvent() has to work, so I catch the pullEvent events and send them back to the running process so I can then use them to do what I need?
Spoiler
-- Main Functions
omi = {}
omi.__index = omi
-- Draw Functions
omi.draw = {}
omi.draw.__index = omi.draw
-- Database (CCSystems) Functions
omi.ccsys = {}
omi.ccsys.__index = omi.ccsys
term.clear()
term.setCursorPos(1, 1)
--[[
tRunning = {{name}, {window}, {thread}}
]]
local thread = {
tRunning = {{},{},{}},
create = function( self, name, func )
table.insert(tRunning[1], name)
table.insert(tRunning[2], window.create(term.current(), 1, 1, 51, 19, false))
if func then
table.insert(tRunning[3], coroutine.create(func))
else
table.insert(tRunning[3], false)
end
return true
end,
resume = function( self, name )
for k, v in ipairs(tRunning[1]) do
if v == name then
if sCurrent then
for k1, v1 in ipairs(tRunning[1]) do
if v1 == sCurrent then
tRunning[2][k1].setVisible(false)
end
end
end
sCurrent = name
tRunning[2][k].setVisible(true)
term.redirect(tRunning[2][k])
if tRunning[3][k] then
coroutine.resume(tRunning[3][k])
end
end
end
end,
list = function( self )
return tRunning
end,
kill = function( self, name )
for k,v in ipairs(tRunning[1]) do
if k == name then
table.remove(tRunning[1][k])
table.remove(tRunning[2][k])
table.remove(tRunning[3][k])
end
end
end,
status = function( self, name )
for k,v in ipairs(tRunning[1]) do
if k == name then
end
end
end,
run = function( self )
end,
}
function omi.init()
local ok, err = pcall( function ()
if http then
if fs.exists("progutils") then
os.loadAPI("progutils")
return true
end
aa = aa or {}
local a = http.get("https://vault.dannysmc.com/lua/api/dannysmcapi.lua")
a = a.readAll()
local env = {}
a = loadstring(a)
local env = getfenv()
setfenv(a,env)
local status, err = pcall(a, unpack(aa))
if (not status) and err then
printError("Error loading api")
return false
end
local returned = err
env = env
_G["progutils"] = env
omi.main()
else
omi.crash("HTTP needs to be enabled.")
end
end)
if not ok then
if nTries == 3 then
print("The program has tried 3 times to get the API, We shall run shell instead.")
sleep(5)
shell.run("clear")
shell.run("shell")
else
nTries = nTries + 1
print("Program, failed to download API, Re-trying...")
sleep(1)
omi.init()
end
end
end
function omi.crash(errcode)
col.screen("white")
draw.box(1, 51, 1, 1, " ", "grey", "grey")
draw.textc(" Omicron has crashed", 1, false, "cyan", "grey")
local sText = "An error has caused Omicron to crash, the error is below, if this happens again, please report the problem and error code to DannySMc (dannysmc95). Error code is stated below in red."
for k,v in ipairs(data.wordwrap(sText, 51)) do
draw.texta(v, 1, k+2, false, "lightGrey", "white")
end
for k, v in ipairs(data.wordwrap(errcode, 45)) do
draw.texta(v, 4, k+8, false, "red", "white")
end
draw.texta("-< Press enter to restart or 's' for shell >-", 4, 19, false, "grey", "white")
while true do
local args = { os.pullEvent() }
if args[1] == "key" then
if args[2] == keys.enter then
omicron.main()
elseif args[2] == keys.s then
shell.run("clear")
shell.run("shell")
end
end
end
end
function omi.draw.loadanimation(intx, inty, txtcol, bkgcol)
if nLoadAnim == 0 then
draw.texta("|", intx, inty, false, txtcol, bkgcol)
nLoadAnim = 1
elseif nLoadAnim == 1 then
draw.texta("/", intx, inty, false, txtcol, bkgcol)
nLoadAnim = 2
elseif nLoadAnim == 2 then
draw.texta("-", intx, inty, false, txtcol, bkgcol)
nLoadAnim = 3
elseif nLoadAnim == 3 then
draw.texta("\\", intx, inty, false, txtcol, bkgcol)
nLoadAnim = 0
end
end
function omi.draw.bar(screenname)
draw.box(1, 51, 1, 2, " ", "grey", "grey")
draw.texta("Omicron:", 1, 1, false, "cyan", "grey")
end
function omi.main()
if term.isColour() then
local ok, err = pcall(function()
--omi.startup()
end)
if not ok then
omi.crash(err)
end
else
omi.crash("Please use an advanced (gold) computer.")
end
end
function omi.startup()
col.screen("black")
sleep(0.15)
col.screen("grey")
sleep(0.15)
col.screen("lightGrey")
sleep(0.30)
draw.textc(" Omicron Operating System", 4, false, "white", "lightGrey")
sleep(0.30)
omi.draw.loadanimation(26, 12, "white", "lightGrey")
os.startTimer(0.15)
while true do
local args = { os.pullEvent() }
if args[1] == "timer" then
omi.draw.loadanimation(26, 12, "white", "lightGrey")
os.startTimer(0.15)
end
end
end
function omi.test()
for i=1, 10 do
textutils.slowWrite(i, 0.5)
end
end
thread:create("test", omi.test)
local th = thread:list()
print(th[1][1])
print(th[1][2])
print(th[1][3])
while true do
for k,v in ipairs(thread:list()) do
print(v[k][v])
sleep(0)
end
end
This was my test and it didn't work, could someone give me examples, as I have had many posts where people explain but I can't get it, so an example would be perfect, I know it's a lot to ask but I would be forever grateful!
Cheers anyone that reads and wants to help :)/>/>/>
I am on irc:
Link: http://webchat.esper.net
Channel: #shinexusuk
so you are welcome to help,
Once again, thanks to anyone that wants to help, I am very keen to learn just it has been months and I still can't figure it out.