Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: planetfall on September 28, 2014, 11:14:02 AM

Title: Regarding having lots of variables
Post by: planetfall on September 28, 2014, 11:14:02 AM
Is there a. any limit on the number of variables per script, and b. significant slowdown with accessing variables when there are a ton of them?

I ask because I need a way to store information about individual cells, for things like the sanctuary shield and some other ideas I have. The way I've found to do this is to have an off-map core with a known UID and a mostly blank script, and the variable names themselves refer to the cell. This seems to be faster than iterating over a single list variable to find the right cell, and more hassle-free than creating nested lists and ensuring they always remain the same size.

However, if it won't work, it won't work. :P
Title: Re: Regarding having lots of variables
Post by: knucracker on September 28, 2014, 02:46:41 PM
Variables in CRPL are stored in an internal hashmap.  So you can have a whole lot of them without any real slowdown.  If you create millions, then a lot of game memory will be used.  But other than that the hashmap is O(1) access time.  (Of course the hashmap has to allocate new memory as it grows, but once done that one-time performance cost is paid).

Title: Re: Regarding having lots of variables
Post by: planetfall on September 28, 2014, 07:03:20 PM
Cool, thanks.