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.
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.