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

getting local variables

Started by blipman17, 07 April 2014 - 05:56 PM
blipman17 #1
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?
CometWolf #2
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
blipman17 #3
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.
Lyqyd #4
Posted 07 April 2014 - 08:35 PM
Well, they are threads, actually. What are you on about, CometWolf?
CometWolf #5
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…
Lyqyd #6
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:".