Forum C# Static Fields are disallowed?

Static Fields are disallowed?

Postby JamesPro » June 12th, 2012, 6:54 pm

I looked online for a Vector3 class I could use on the server for player and mob positions and that would include all the helper methods for finding distance and things like that. I found one and copied it into a Vector3 class in my server code. I then start up my development server and find out that Static Fields are not Allowed? Why aren't they allowed?
JamesPro
 
Posts: 13
Joined: June 6th, 2012, 5:01 am

Re: Static Fields are disallowed?

Postby beezir » June 12th, 2012, 9:32 pm

From this thread:
We're sorry about that, but if we allowed static variables, people would drop in third-party libraries, they would have no clue if state is shared globally, and get very strange behaviour as separate rooms sometimes would affect one another. That's a support nightmare.

But great work on refactoring the library! Now you can be certain that it will work without strange side-effects for your game.


Sounds like it's due to the fact that static vars could be shared across rooms. I'm assuming each customer is isolated on the back-end, but if not, global state would allow one customers rooms to affect another's.
beezir
 
Posts: 6
Joined: June 7th, 2012, 2:47 am

Re: Static Fields are disallowed?

Postby dreamora » June 12th, 2012, 11:02 pm

The problem is also that it wouldn't even be consistent for yourself as your rooms will end up on multiple machines in which case the static would no longer be shared either.
dreamora
 
Posts: 225
Joined: March 2nd, 2012, 9:58 am


Return to C#



cron