Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
XanderRadio

constant program running in background as service

Question

i want to control something using opencomputers that requires it to constantly check something and act based on that input but i want to be able to do other things as well so it needs to run in the background and run constantly without using a while true do loop as i don't want it to interfere with any other background programs i have running, please help if you can.

Link to post
Share on other sites

8 answers to this question

Recommended Posts

  • 0
2 minutes ago, Molinko said:

Could you clarify what exactly you expect?? I showed you one option in another thread for a service that launches programs into the background. Was that not what you're looking for?

it gave this error: 2018-06-16_23_13_43.thumb.png.c37b5e4fd8df999eb7440cc1590bb12e.png i have no clue what the problem is...

Link to post
Share on other sites
  • 0
9 minutes ago, Molinko said:

Seems you're on an older version of OpenOS. Sorry, but my example would require the thread library in order to function. If you update your OC version and reinstall OpenOS It should fix the issue.

rather annoyingly Opencomputers got threads added in an update later than 1.7.10 meaning that i can't use threads, any chance it could work with coroutines in a similar way?

Link to post
Share on other sites
  • 0

Sorry but it would take a ton of work.. Basically the thread library is a fancy coroutine library that let you do fancy things.. like detach a process from the current process and attach it to the parent.. One possible option is to update OpenOS itself. A newer version of the OS should work with an older version of OC. Check out this thread .... (OpenOS updater)

Link to post
Share on other sites
  • 0

98.3% of opencomputers seems to be a constant stream of errors... this is one of those times, this means that i will have to look for alternate solutions.... technically all i want to do is have a computer run a piece of code every so often but in a way that doesn't interfere with other programs i have running, in short i need a loop that won't act as while true do in the sense that it won't prevent me from doing anything else but it still runs in a loop. i've been overcomplicating things..

Link to post
Share on other sites
  • 0

You might want to look into something like event.listen or event.timer.

Basically every time an event occurs you can have a block of code run. Here's a small example.

local event = require "event"

local function printComp(ev, addr, ctype)
  print(string.format("component added: [type] %s  [address] %s", ctype, addr))
end

event.listen('component_added', printComp)

-- some time later
event.ignore('component_added', printComp)

Here's a timer example.

local event = require "event"

local count = 0

local handle = event.timer(1, function()
  count = count + 1
  print(string.format("timer tick #%d", count))
end, 10) -- # (how often, callback(), how many times)

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.