Jump to content




Multitasking Help

api lua help

  • You cannot reply to this topic
8 replies to this topic

#1 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 07 April 2015 - 02:38 PM

Hello, yes I am back.

I made a script and got a little 'stuck' when I attempt to create a process, it seems to switch to it? But I only want it to make it, I don't wish to switch to it? Also it seems that it won't actually resume threads either and redraw the window? Any ideas? Thanks

Code:
Spoiler


#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 April 2015 - 02:52 PM

One thing that's weird, why are you setting
tbl.__index = tbl
?

It doesn't do anything special, and you never access the __index key.

Edit: Also, there is no thread:goto function that I can see...

Edited by KingofGamesYami, 07 April 2015 - 02:58 PM.


#3 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 07 April 2015 - 03:19 PM

View PostKingofGamesYami, on 07 April 2015 - 02:52 PM, said:

One thing that's weird, why are you setting
tbl.__index = tbl
?

It doesn't do anything special, and you never access the __index key.
Edit: Also, there is no thread:goto function that I can see...

Where is this sorry?:s

Also yes I mean to use resume, but still it keeps running a process? When I only create it?:s

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 April 2015 - 03:58 PM

omni.startup uses thread:goto( "desktop" )

Also, why do you have windows if you never redirect or draw any of them?

#5 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 07 April 2015 - 04:35 PM

View PostKingofGamesYami, on 07 April 2015 - 03:58 PM, said:

omni.startup uses thread:goto( "desktop" )

Also, why do you have windows if you never redirect or draw any of them?

I do?:s When I use thread:resume() it automatically redraws the window.
A window is created with a coroutine and name when using thread:create().

Here is the updated code, hasn't changed; still running the co routines when I create them.
Spoiler

Edited by DannySMc, 07 April 2015 - 04:36 PM.


#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 April 2015 - 05:29 PM

        resume = function( self, name )
                for k, v in ipairs(self.tRunning[1]) do
                        if v == name then
                                if self.sCurrent then
                                        for k1, v1 in ipairs(self.tRunning[1]) do
                                                if v1 == self.sCurrent then
                                                        self.tRunning[2][k1].setVisible(false)
                                                end
                                        end
                                end
                                self.sCurrent = name
                                self.tRunning[2][k].setVisible(true)
                                self.tRunning[2][k].redraw()
                                term.redirect(self.tRunning[2][k])
                                if self.tRunning[3][k] then
                                        coroutine.resume(self.tRunning[3][k])
                                end
                        end
                end
        end,
...is so completely wrong based on what I've told you in other topics, I just don't know anymore...

To clarify:

#1 - you resume only a single coroutine
#2 - you never use events
#3 - you never capture filters
#4 - this works exactly the same as if you had never turned it into a coroutine and just called it, except it doesn't get to finish what it's doing before it returns/yields... and 1-3

Edited by KingofGamesYami, 07 April 2015 - 06:38 PM.


#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 April 2015 - 09:51 PM

If memory serves, he doesn't want his multi-tasking engine to run "background processes". Rather, he wants all processes except the current one to basically be paused until they become the active process again.

Which unfortunately leads to issues with timer events, which can't really be discarded. Putting aside that he's still discarding all events.

View PostBomb Bloke, on 23 March 2015 - 11:50 PM, said:

If it helps, think of a coroutine as a function which returns every single time it yields, but until it returns "properly", it can be resumed from where it left off. Every time it yields, it's able to return data - think of coroutine.yield("char") (or os.pullEvent("char"), they boil down to nearly the same thing) as being sorta like return "char" - and every time it resumes, it expects data back - think of coroutine.resume(myFunc, "char", "p") as being sorta like myFunc("char", "p").


#8 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 07 April 2015 - 09:58 PM

View PostKingofGamesYami, on 07 April 2015 - 05:29 PM, said:

		resume = function( self, name )
				for k, v in ipairs(self.tRunning[1]) do
						if v == name then
								if self.sCurrent then
										for k1, v1 in ipairs(self.tRunning[1]) do
												if v1 == self.sCurrent then
														self.tRunning[2][k1].setVisible(false)
												end
										end
								end
								self.sCurrent = name
								self.tRunning[2][k].setVisible(true)
								self.tRunning[2][k].redraw()
								term.redirect(self.tRunning[2][k])
								if self.tRunning[3][k] then
										coroutine.resume(self.tRunning[3][k])
								end
						end
				end
		end,
...is so completely wrong based on what I've told you in other topics, I just don't know anymore...

To clarify:

#1 - you resume only a single coroutine
#2 - you never use events
#3 - you never capture filters
#4 - this works exactly the same as if you had never turned it into a coroutine and just called it, except it doesn't get to finish what it's doing before it returns/yields... and 1-3

Oh I want to be able to like say thread:resume(processname) and then it runs that process, and then I can switch between multiple ones? I think?

#9 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 07 April 2015 - 10:45 PM

What you'd do is you'd have a function that sets a variable, then yield. The manager (which is running aforementioned code) uses that variable to determine which events to give to what. This means everything is running at the same time, you can't stop something from running because that causes major problems.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users