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

[Lua] How much does depth of the stack effect calculation speeds?

Started by scubadiver1991, 30 March 2013 - 03:52 PM
scubadiver1991 #1
Posted 30 March 2013 - 04:52 PM
Title: [Lua] How much does depth of the stack effect calculation speeds?
So I'm fiddling around with my first somewhat complex program and I wrote a function that uses the math.random() function a few times to assign variables values from some pre-defined tables. Basically, it's a name generation function.

When I run it by itself I don't run into any issues, but as soon as I called it from within another function I started running into attempt to concatenate nil and string errors every now and then when the function attempted to print the final name. I ended up fixing the problem with a simple sleep() call, but by my count that isn't even very deep in the stack. Does the depth have that much of an influence on how fast the calulations go, and for that matter, why is the code proceeding when it hasn't assigned anything to those variables?

I'm writing a psuedo rogue-like to kill time while I wait for my turtles to finish projects I send them on, so I imagine I'll be using the math.random() function a lot, so I suppose my real question is if there is a more effecient and more reliable way I could be doing this?

The problem function:
http://pastebin.com/ci9xhbCb

I apologize if my code is a mess, I've been throwing this together in a void without any real feedback. You are more than welcome to point out any problems with how I'm going about this.

edit: I corrected the name of my error. I don't have the error code, but if it's absolutely neccisary I could recreate it.
Lyqyd #2
Posted 02 April 2013 - 04:49 AM
Split into new topic.

I'd like to see both the working code when the function is by itself, and the non-working code when it's included in the program, as well as the full text of the error message.
Ray_Anor #3
Posted 02 April 2013 - 08:14 PM
look at thi code part

  cFName = nil
  cSuffix = nil
  cLName = nil
  term.clear()
  term.setCursorPos(1 , 1)
  hExistBool = True
  cFName = namesF[math.random(1 , 61)]   --(These are how the names are randomized, at this point the name is  split into seperate variables, that will change soon, that is why these are local)
  cSuffix = namesS[math.random(1 , 4)]
  cLName = namesL[math.random(1 , 38)]
  hFame = 0			    --(These are the stats for the hero)

if your other functions working fine it's must work now

local and no local variables there is a porblem