🎉 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!

A few ways to make GetGlobalVarPointer() a bit more useful

Started by
1 comment, last by Zoma 18 years, 5 months ago
I'm trying to use GetGlobalVarPointer() in order to allow for scripters (read: probably me) to save/load script defined variables with the user data (in other words, game saves). Maybe I'm missing the boat, but it seems like in order to use the void* returned by this function, I'd have to get the var declaration, then get the type declaration, and then have my own routine that returns sizes based on the type declaration. This isn't too bad, but I'd rather avoid having to assume my sizes are correct, especially for AS definied types. It seems like there are a few ways AS could provide some more data to avoid this. One would be a GetTypeSize() function that returns the size of a typeID in bytes. Another way would be to have a GetGlobalVarValueString() function that returns a const char* containing the value of the variable as a string.
Advertisement
The GetTypeSize() suggestion is definitely a good thing. I'll put that on my to-do list.

I'm not so sure about the GetGlobalVarValueString() though. I do not think it would be very useful. Most developers would likely prefer to store the binary value of the variable, especially since for floats and doubles you wouldn't get the exact value. Besides, it wouldn't work at all for complex types.

Regards,
Andreas

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

Yeah, the more I thought about it, the more I realized that getting the size is much better.

For those interested, I ended up having several overloaded functions that work by passing a name/value pair. The value isn't really needed, but the overloaded function lets me know what type it is. It ended up being pretty cool - I have a persist function that stores variables, even after the module is cleared.

I also used a similar method to added run-time debugging watch values. My implementation works for now, but it appears that if I wanted to improve the system to not use overloaded functions, I'd still have to do some sort of processing on the type string. For instance, say I knew the size of the data was a byte. It's string representation could be a char or bool. Or worse, a std::string or other class that has an arbitrary size.

This topic is closed to new replies.

Advertisement