92 posts
Posted 07 April 2014 - 07:56 PM
I understand the idea behind local variables and am using them like mad. but can I somehow get them like i shouldn't. something like print(generalise(varablename)), so I can use it for an GUI that is running as a second thread, without redesigning my whole code? Or is there a better way?
1281 posts
Posted 07 April 2014 - 08:06 PM
I just wanna smack people who refer to parallel as a second thread! Anyways, the whole point of local variables is that they are inacessible outside of their scope. If you need acess to a variable from outside it's scope, don't localize it to that scope.
local derp --localized to the program scope
funciton test()
derp = 2
end
function test2()
derp = derp+2
end
test()
test2()
print(derp) --prints 4
92 posts
Posted 07 April 2014 - 08:13 PM
parallel isn't a second thread? okay, good to know.
I think that I will have to unlocalise a lot of variables for the next hour.
than you wolf.
8543 posts
Posted 07 April 2014 - 08:35 PM
Well, they are threads, actually. What are you on about, CometWolf?
1281 posts
Posted 07 April 2014 - 08:39 PM
My definition of a thread would be something that runs simulteanously, though now that i think about it, i might've mixed up the terms multi-threads and just plain threads…
8543 posts
Posted 07 April 2014 - 08:45 PM
Well, since the ComputerCraft computers all share one "core" per server, there certainly isn't anything that can run simultaneously with anything else, just like any regular single-core computer. Each coroutine is still an individual thread, though. Amusingly enough, tostring()ing a coroutine happens to be similar to doing so on a table or function, but they're labeled "thread:".