Advertisement Jump to content
Sign in to follow this  
wilberolive

Expression must be of boolean type?

This topic is 1787 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

?

I'm just wondering why the following code fails with "Illegal operation on this datatype" and "Expression must be of boolean type" errors. I understand what the errors mean. I'm more so wondering why the VM isn't smart enough to be able to evaluate zero as false and non-zero as true? Unless I'm missing something?

int test = 0;
if(!test)
   test = 1;

Share this post


Link to post
Share on other sites
Advertisement


… why the VM isn't smart enough to be able to evaluate zero as false and non-zero as true ...

I'm not familiar with AngelCode, but using 0 as boolean false and any other integer value as boolean true is a convention introduced by programming languages that does not support a boolean type natively. If a boolean type is supported, then any automatic conversion to boolean is a language feature. Not doing so allows for greater type safety, doing so allows for greater convenience. I won't say that a particular language is not smart because it lacks such automatic conversion.

Share this post


Link to post
Share on other sites

It is like this by design.

 

I chose not to allow implicit conversion of any type to or from bool in AngelScript because it is a very common cause for bugs in C++, especially with beginner programmers.

Share this post


Link to post
Share on other sites

OK, thanks guys. Just wanted to make sure I understood what was going on.

 

Sorry for using "not smart." I'm not an expert on the inner workings of languages and compilers. Thanks for the info haegarr.

Share this post


Link to post
Share on other sites

Fun examples of languages that don't follow the zero is false convention are ruby, where every integer including zero evaluates to true (only False and nil evaluate as false) and most shell scripting languages where zero is true and non-zero is false.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!