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

Conversion through assignment

Started by
2 comments, last by WitchLord 19 years ago
Hey, I've been implementing some scripting using angelscript [and it's really been a pleasure to work with] and have come up to the point that I need to convert between types. Now, this is relatively trivial for defined types, where you can simply register an assignment operator. However, I can't seem to register any assignment operators for the intrinsic types - my test was with "int" but it all works if I register a type "sint" and use that instead. Is it possible to define behaviors for the intrinsic types, or am I doing something wrong? I figure that I can use a conversion function, but it would be nice if I could just use equals. I read in the changelog? that improved implicit and explicit casting is somewhere in the books, but the version that I'm using is [slightly] modified from the original and as such I think it's quite old. I know I really should get a newer version, but the one that I'm using has worked fine so far, so unless there's a reason [that I hit] to upgrade it's on the backburner for the moment. My question is, will updating help me; am I doing something wrong; or should I just make my own conversion functions which aren't registered as assignment operators? Thanks in advance, CJM
Advertisement
Just like in C++, AngelScript doesn't allow you to change the operators for intrinsic types. However, C++ does allow you to implement casting operators for your types, this is something that AngelScript still doesn't have but will probably have in the future.

If your version is pre 1.10.1d then I suggest you at least upgrade to that one, as the implicit conversions between intrinsic types was implemented with that version.

Version 2.1.0c, which is the current stable version, doesn't change the way implicit conversions work, but it does provide a more secure environment for your scripts.

For now the best way to convert registered types into intrinsic types is to have either a global function that does the conversion or a method on the type.

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

Hey,

Thanks, I'll probably just end up either creating a global conversion function which I call manually, or redefining all of the primitive types that I use for all of my functions and putting in assignment operators for those.

[For those who were interested, the reason that I was wanting it was for my console variables, which automagically do other stuff when you change their value, like if you change the data part (an external pointer) of "Var<bool> consoleVisible" to false, the system automatically hides the console and runs all associated stuff. The problem was allowing functions such as "void func(bool)" to access the boolean within the variable. I currently have to use "func(consoleVisible.value())" which is no big issue but it does keep reminding the scriptwriter that it isn't actually a boolean after all.]

Needless to say though, AngelScript is IMO _the best_ scripting system out there [mainly because it's typed and I can more or less put unchanged C code in there and have it work]. Thanks for the reply, and keep up the great work.

CJM
I have plans to support get/set function pairs for properties. To the script these will look just like normal properties, but behind the scene they actually call a function instead. But this is probably quite far away yet since there is so many other things that I consider more important.

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

This topic is closed to new replies.

Advertisement