Jump to content




getting local variables


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

#1 blipman17

  • Members
  • 92 posts

Posted 07 April 2014 - 06: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?

#2 CometWolf

  • Members
  • 1,283 posts

Posted 07 April 2014 - 07: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


#3 blipman17

  • Members
  • 92 posts

Posted 07 April 2014 - 07: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.

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 April 2014 - 07:35 PM

Well, they are threads, actually. What are you on about, CometWolf?

#5 CometWolf

  • Members
  • 1,283 posts

Posted 07 April 2014 - 07: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...

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 April 2014 - 07: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:".





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users