eXodus
11-12-2006, 03:42 AM
The intricacies of script-scope variables have been talked about a lot, but what of instance-scope? I am working on a Beamos script and I need to store the direction each one is looking separately; hence it is currently declared in void run(...) as float currDir. However, whenever I call another function - void turn(int) - in the same script, it is unable to find either currDir or this->currDir. I know turn() is technically outside of run()'s scope, but that's where the problem lies.
I would normally solve this in one of two ways - pass the variable as a reference parameter or declare turn() inside run(). I can't remember if the latter is possible in C/C++, but it didn't work here. From what I've read, pointers to primitives are intentionally unavailable, but doesn't that mean you can't pass parameters by reference either? Short of copying the contents of the function to every point it's called, I can't see any other way to access variables declared in run(), and that doesn't help if/when the function is called at least 10 times (not the case here yet)...
I would normally solve this in one of two ways - pass the variable as a reference parameter or declare turn() inside run(). I can't remember if the latter is possible in C/C++, but it didn't work here. From what I've read, pointers to primitives are intentionally unavailable, but doesn't that mean you can't pass parameters by reference either? Short of copying the contents of the function to every point it's called, I can't see any other way to access variables declared in run(), and that doesn't help if/when the function is called at least 10 times (not the case here yet)...