Archived

This topic is now archived and is closed to further replies.

Desdemona

AngelScript + bools

Recommended Posts

Desdemona    158
I'm having a problem with bools in v1.6.1... If I use global properties, they work as expected. The folllowing prints out 'false true false true'
   // In the program

   m_pEngine->RegisterGlobalProperty("bool g_bMyBool", &g_bMyBool, 0);

   // In the script

   g_bMyBool = false;

   if (g_bMyBool)  Console.Write("true\n");
   else            Console.Write("false\n");
      
   g_bMyBool = true;   

   if (g_bMyBool)  Console.Write("true\n");
   else            Console.Write("false\n");
      
   g_bMyBool = false;   

   if (g_bMyBool)  Console.Write("true\n");
   else            Console.Write("false\n");
      
   g_bMyBool = true;   

   if (g_bMyBool)  Console.Write("true\n");
   else            Console.Write("false\n");
But if I try and use a bool as an object property, things dont work quite right.
   Scripting.GetEngine().RegisterObjectType("CSPhysics", 0, 0);
   Scripting.GetEngine().RegisterGlobalProperty("CSPhysics Physics", this, 0);
   Scripting.GetEngine().RegisterObjectProperty("CSPhysics", "bool Enable", offsetof(CSPhysics, m_bEnable), 0);
If I did the same test as before, AngelScript will always read the bool 'Physics.Enable' as 'true'. I can assign values to 'Physics.Enable' and those values are applied correctly, but it is only read as true. D [edited by - Desdemona on March 22, 2004 9:47:58 PM] [edited by - Desdemona on March 22, 2004 9:48:32 PM]

Share this post


Link to post
Share on other sites
WitchLord    4678
The latest version 1.6.1 fixes a bug with the boolean type where AngelScript was using 4 bytes, when it should have been only 1. It could be that this is a part of that bug that was missed. I''ll do some more extensive testing with the boolean type to see if I can identify anymore bugs.

Oh, and about the boolean operators in AngelScript that you are having trouble with. They are as follows:


AS : C++
and : &&
or : ||
not : !


Thus in angelscript you would write:

bool var = false;
if( not var )
{
do something...
}

Regards,
Andreas

__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library

Share this post


Link to post
Share on other sites