🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Static / shared class or global variables

Started by
2 comments, last by noizex 4 years, 7 months ago

Hello,

I just realized that Angelscript does not really have a 'static' class variables like most languages. What would be the best approach to achieve a variable that will be shared among all instances? I tried to define global int but then it would not allow it because the class accessing it is shared. If I make it shared it doesn't compile - is it because global variables can't be shared yet? I tried looking through the changelog and documentation and could not find anything :(

This is sadly rather limiting, and the only other idea I have is introducing some artificial "variable storage" that would work externally, but it feels a bit like reinventing the wheel. 


Where are we and when are we and who are we?
How many people in how many places at how many times?
Advertisement

Shared global variables are not yet supported, but it is on my to-do list.

Static class members are just global variables in the namespace of the class, so even if static members were supported they would suffer the same limitation as global variables.

You can have a non-shared class implement a shared interface. The non-shared class will be able to use global variables normally, and the shared interface will allpw you to share the instance across script modules.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks for reply! To be honest, I was aiming for 100% shared thing, almost as far as shared by default abecause it's just easier and more convenient to use. So having to specify interface for final class just to be able to have global variable available seems like too big a tradeoff.

I'll probably implement some special storage class for such global variables as a singleton that can be accessible till global variables become shareable.

Something like:

globals.get<int>("myintvar")

Where are we and when are we and who are we?
How many people in how many places at how many times?

This topic is closed to new replies.

Advertisement