Static Variables?

Jul 24, 2008 at 9:23 PM

The "Advanced Developer Guide" states:

"Some features that are explicitly denied are the use of finalizers or class destructors, static variables which could be used to allow creatures of the same species to talk, and the loading of the organism into a secured AppDomain where many privileges such as reflection, network IO, and file IO."

My question is about static variables.  The 2.0 release allows static variables enabling creatures to communicate.  Is this priveledge around for good or are there plans to remove it?  The reason that I ask is that I'd like to make creatures that will collude, but do not want to invest too much time in it if static variables will be banned in the next release.

Jul 27, 2008 at 7:44 AM
Allowing some sort of creature cooperation would add an interesting (if complicated) dynamic. However, the problem is not creature cooperation; it is that type static variables would allow creatures of the same type to share data in a manner which is completely out of the control of the game engine. For example, if every time a creature scanned its surroundings, it added everything it could see to some type of static storage, then other creatures of the same type would have access to that data, even though according to the rules of the game they might not be able to see those creatures. If creature cooperation is to be allowed, it must be facilitated through some mechanism that the game can control, rather than through sharing static data.

As an aside, a better way to disallow this type of behavior, rather than prohibiting static variables, might be to load each individual creature into its own AppDomain. Since static variables are not shared across AppDomains, no data sharing would be possible. This would also have the additional advantage of providing a safe way to remove malicious or misbehaving creatures from the game, while keeping the game running and even allowing other instances of the creature to remain (if appropriate). The downside would be that the organism assembly would have to be loaded once per AppDomain, instead of once for the entire application, which would increase the memory load; however, since organism assemblies should generally be light, this might not be a big problem. There would also obviously be performance implications, but these may be manageable as well. I will make an attempt and see what happens.
Jul 28, 2008 at 5:18 PM
Static variables do seem a little like cheating to me.  It would be cool to have a truly "hive mind" type of creature, but I'm not sure it is fair.  I know the antenna mechanism isn't great, but it is a start and can be used to communicate between animals.  Maybe it could be configurable on the server.

Putting each animal in its own AppDomain would be too expensive, IMO.  Each creature has little overhead, but it still has to load other libraries and structures (OrganismBase, Animal, etc.)  I think you're better off using Reflection, which can detect static variables.  A little upfront cost of poking around inside the creature and then you're done.  I could see later versions of the Terrarium interrogating the animal on multiple levels before allowing it to load.
Jul 28, 2008 at 7:33 PM
Actually you can do a lot with the Antenna, I just seen this game is realeased again and thrilled with it I had had a ton of fun with the older version just waiting to see what I can do now. But if any of you remember the top carnivores all had antenna going and active and hunted in packs. They had to in order to survive in a bug eat bug world. There were even some open source modules to help with it, but with the speed limitation of the code you didn't have too much time for communication. The most I could ever get communicating at once was 6 bugs but they spent so much time communicating they had trouble navigating around objects still it was cool to watch your code communicate with itself and plan out attacks. In reality this way of communication while more of a challenge does get you a hive mind.

I do not want to reveal all my tricks but some of the limitations I had to overcome was by pack hunting, finding a leader, who would then issues orders which included passing the torch or adding new members, this would keep the packs going. However communicating also wasted vital tick count time as you had to be sure each creature seen orders. so the leader may hold a command for 2 tick counts.

So static variable would be a way of cheating and removing some of the challenge to the game. The only thing really limiting to this is your own imagination and coding ability.