Sign in to follow this  

Automatic integer - bool convertion

This topic is 3192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! One of the things I find utterly strange in AngelScript is the inability to simply write:
int a;
...
if (a)
{

Why am I always forced to write:
int a;
...
if (a != 0)
{

or
...
if ((a & 1) != 0)
{

instead? This is very unfriendly to end-programer and counter-intuitive. Is there any possibility this feature will be implemented in the near future?

Share this post


Link to post
Share on other sites
You're thinking like a C++ programmer. It's not so counter intuitive for non-C++ programmers, and actually quite common cause for bugs with inexperienced programmers.

However, I can add a engine property to allow the application developer to choose if these conversions should be allowed or not.

Share this post


Link to post
Share on other sites
Like Andreas said, it is a cplusplusy thing. As soon as you try out C# you'd find the same thing as AngelScript.
ints are not bools and you are making a technical assumption that the value of False is the same as integer zero and True is any other value. (which, for the most part is always right)

Share this post


Link to post
Share on other sites
it's not only it's a C++ thing, it's also a C thing, a PHP thing, a javascript thing, insert_language_of_your_preference thing.

Quote:
Original post by midniteAs soon as you try out C#
I have and I don't think I'll ever come back to it :)

Share this post


Link to post
Share on other sites
On this subject, one thing that always bugs me off is that some operations with enum defined values generate errors at compile time. We use enums to "feed" the script with all kind of predefined values, many being bitflags, and operating with these bitflags can be pretty ugly at times. Example of compiling:

gametype.spawnableItemsMask &= ~G_INSTAGIB_NEGATE_ITEMMASK;

The negation is a illegal operation. I asume this is cause it tries to negate the enum value itself, so it fails. I use this trick to force it to generate a copy of itself to operate (well, that's my guess):

gametype.spawnableItemsMask &= ~uint(G_INSTAGIB_NEGATE_ITEMMASK);

Then it works. But it's pretty ugly to have to add the cast every time we want to use some of the predefined bitflag constants. Do you think it would be possible/convenient to force it to generate the copy on that kind of operations?

[Edited by - jal_ on March 16, 2009 6:08:27 AM]

Share this post


Link to post
Share on other sites

This topic is 3192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this