Advertisement

Question about casting and constructors for objects

Started by April 09, 2009 11:02 PM
7 comments, last by WitchLord 15 years, 7 months ago
You know how in C++ you can do this for classes?

class Something
{
  public:
  Something(int value);
  Something(float vlaue);
  Something(const std::string& value);
  Something(const Something& value);

  Something& operator=(const Something& value);
  Something operator+(const Something& value);
};
Notice for the operator overloads of "=" and "+" i only overloaded it for "const Something& value" but if i tried to do this in C++:

Something test;
test = 32;
It would still work because the compiler will automatically do this:

Something test;
test = Something(32);
Because constructors exist for "int", "float" and "std::string" i don't have to create an operator overload for each one of them. Is this possible in angelscript? I tried it with asBEHAVE_FACTORY and asBEHAVE_ASSIGNMENT and it didn't work. I have this object that i want to work with several different datatypes but i don't want to create operator overloads for each data type it can work with. The only place it doesn't work is functions like printf that doesn't have defined parameter types. [Edited by - 39ster on April 14, 2009 8:48:07 AM]
Here's what i tried when registering the object:

void RegisterScriptVariable(asIScriptEngine *engine){	int r = 0;    // Register the type	r = engine->RegisterObjectType("var", sizeof(ScriptVariable), asOBJ_REF); assert( r >= 0 );	// Register the constructors	r = engine->RegisterObjectBehaviour("var", asBEHAVE_FACTORY,    "var@ f()",                  asFUNCTION(VariableDefaultFactory), asCALL_GENERIC); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_FACTORY,    "var@ f(uint)",               asFUNCTION(VariableIntFactory), asCALL_GENERIC); assert( r >= 0 );	r = engine->RegisterObjectBehaviour("var", asBEHAVE_FACTORY,    "var@ f(const var& in)",     asFUNCTION(VariableCopyFactory), asCALL_GENERIC); assert( r >= 0 );    //Register add/release stuff	r = engine->RegisterObjectBehaviour("var", asBEHAVE_ADDREF,     "void f()",                  asFUNCTION(VariableAddRef), asCALL_GENERIC); assert( r >= 0 );	r = engine->RegisterObjectBehaviour("var", asBEHAVE_RELEASE,    "void f()",                  asFUNCTION(VariableRelease), asCALL_GENERIC); assert( r >= 0 );    //Register the assignment operator	r = engine->RegisterObjectBehaviour("var", asBEHAVE_ASSIGNMENT, "var& f(const var& in)",     asFUNCTION(VariableAssign), asCALL_GENERIC); assert( r >= 0 );}


Heres the angelscript code:
var test = 32; //Note "var test(32)" works


Here's the error:
Loading plugins... (3, 9) : INFO : Compiling var test (3, 11) : ERR  : Can't implicitly convert from 'const uint' to 'var&'.Unable to load plugin: Server
Advertisement
I still need to implement implicit factory/constructor behaviour to allow the implicit cast from primitive value to an object type.

The otherway around is already working, i.e. implicit cast from object type to primitive type, and also between object types. To implement that you use the implicit value cast behaviour, i.e. asBEHAVE_IMPLICIT_VALUE_CAST.

I'll raise the priority for implementing the implicit factory/constructor behaviours.

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

Awesome. Do you think it would be possible to implement this class once you're done?

#ifndef VARIABLEH#define VARIABLEH#include <string>class Variable{public:    enum {        TYPE_INTEGER = 0,        TYPE_FLOAT,        TYPE_STRING    };private:    union {        int             value_int;        float           value_float;        std::string*    value_string;    } data;    char    type;    void FreeString() {        if(type == TYPE_STRING)            delete data.value_string;    }public:    Variable(int value = 0) {        type = TYPE_INTEGER;        data.value_int = value;    }    Variable(float value) {        type = TYPE_FLOAT;        data.value_float = value;    }    Variable(const std::string& value) {        type = TYPE_STRING;        data.value_string = new std::string(value);    }    Variable(const char* value) {        type = TYPE_STRING;        data.value_string = new std::string(value == NULL ? "" : value);    }    Variable(const Variable& value) {        type = value.type;        switch(type)        {            case TYPE_STRING:                data.value_string = new std::string(*value.data.value_string);            break;            default:                data = value.data;        }    }    ~Variable() {        FreeString();    }    operator int() const {        return ToInt();    }    operator float() const {        return ToFloat();    }    operator std::string() const {        return ToString();    }    size_t Size() const {        switch(type)        {            case TYPE_INTEGER:                return sizeof(data.value_int);            break;            case TYPE_FLOAT:                return sizeof(data.value_float);            break;            case TYPE_STRING:                return data.value_string->size();            break;        }        return 0;    }    int GetType() const {        return type;    }    bool IsInt() const {        return type == TYPE_INTEGER;    }    bool IsFloat() const {        return type == TYPE_FLOAT;    }    bool IsString() const {        return type == TYPE_STRING;    }    static int ToInt(int value) {        return value;    }    static int ToInt(float value) {        return int(value);    }    static int ToInt(const std::string& value) {        return atoi(value.c_str());    }    static int ToInt(const char* value) {        return atoi(value == NULL ? "" : value);    }    static Variable ToInt(const Variable& value) {        return value.ToInt();    }    static float ToFloat(int value) {        return float(value);    }    static float ToFloat(float value) {        return value;    }    static float ToFloat(const std::string& value) {        return atof(value.c_str());    }    static float ToFloat(const char* value) {        return atof(value == NULL ? "" : value);    }    static Variable ToFloat(const Variable& value) {        return value.ToFloat();    }    static std::string ToString(int value) {        char buffer[1024];        sprintf(buffer, "%i", value);        return buffer;    }    static std::string ToString(float value) {        char buffer[1024];        sprintf(buffer, "%f", value);        return buffer;    }    static std::string ToString(const std::string& value) {        return value;    }    static std::string ToString(const char* value) {        return value == NULL ? "" : value;    }    static Variable ToString(const Variable& value) {        return value.ToString();    }    int ToInt() const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int;            break;            case TYPE_FLOAT:                return ToInt(data.value_float);            break;            case TYPE_STRING:                return ToInt(*data.value_string);            break;        }        return 0;    }    float ToFloat() const {        switch(type)        {            case TYPE_INTEGER:                return ToFloat(data.value_int);            break;            case TYPE_FLOAT:                return data.value_float;            break;            case TYPE_STRING:                return ToFloat(*data.value_string);            break;        }        return 0.0f;    }    std::string ToString() const {        char buffer[64];        switch(type)        {            case TYPE_INTEGER:                return ToString(data.value_int);            break;            case TYPE_FLOAT:                return ToString(data.value_float);            break;            case TYPE_STRING:                return *data.value_string;            break;        }        return "";    }    static Variable AutoType(const Variable& value) {        if(value.IsString())        {            bool isFloat = false;            for(size_t i = 0; i < value.Size(); ++i)            {                if(value == '.')                    isFloat = true;                else if(!(isdigit(value) || value == '-' || value == '+'))                    return value;            }            if(isFloat)                return float(value);            return int(value);        }        return value;    }    Variable& operator=(int value) {        FreeString();        type = TYPE_INTEGER;        data.value_int = value;        return *this;    }    Variable& operator=(float value) {        FreeString();        type = TYPE_FLOAT;        data.value_float = value;        return *this;    }    Variable& operator=(const std::string& value) {        FreeString();        type = TYPE_STRING;        data.value_string = new std::string(value);        return *this;    }    Variable& operator=(const char* value) {        FreeString();        type = TYPE_STRING;        data.value_string = new std::string(value == NULL ? "" : value);        return *this;    }    Variable& operator=(const Variable& value) {        FreeString();        type = value.type;        switch(type)        {            case TYPE_STRING:                data.value_string = new std::string(*value.data.value_string);            break;            default:                data = value.data;        }        return *this;    }    bool operator==(int value) const {        return value == ToInt();    }    bool operator==(float value) const {        return value == ToFloat();    }    bool operator==(const std::string& value) const {        return value == ToString();    }    bool operator==(const char* value) const {        return std::string(value == NULL ? "" : value) == ToString();    }    bool operator==(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return operator==(value.ToInt());            break;            case TYPE_FLOAT:                return operator==(value.ToFloat());            break;            case TYPE_STRING:                return operator==(value.ToString());            break;        }        return false;    }    bool operator!=(int value) const {        return !(*this == value);    }    bool operator!=(float value) const {        return !(*this == value);    }    bool operator!=(const std::string& value) const {        return !(*this == value);    }    bool operator!=(const char* value) const {        return !(*this == value);    }    bool operator!=(const Variable& value) const {        return !(*this == value);    }    bool operator>(int value) const {        return ToInt() > value;    }    bool operator>=(int value) const {        return ToInt() >= value;    }    bool operator<(int value) const {        return ToInt() < value;    }    bool operator<=(int value) const {        return ToInt() <= value;    }    bool operator>(float value) const {        return ToFloat() > value;    }    bool operator>=(float value) const {        return ToFloat() >= value;    }    bool operator<(float value) const {        return ToFloat() < value;    }    bool operator<=(float value) const {        return ToFloat() <= value;    }    bool operator>(const std::string& value) const {        return ToString() > value;    }    bool operator>=(const std::string& value) const {        return ToString() >= value;    }    bool operator<(const std::string& value) const {        return ToString() < value;    }    bool operator<=(const std::string& value) const {        return ToString() <= value;    }    bool operator>(const char* value) const {        return ToString() > std::string(value == NULL ? "" : value);    }    bool operator>=(const char* value) const {        return ToString() >= std::string(value == NULL ? "" : value);    }    bool operator<(const char* value) const {        return ToString() < std::string(value == NULL ? "" : value);    }    bool operator<=(const char* value) const {        return ToString() <= std::string(value == NULL ? "" : value);    }    bool operator>(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int > value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float > value.ToFloat();            break;            case TYPE_STRING:                return *data.value_string > value.ToString();            break;        }        return false;    }    bool operator>=(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int >= value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float >= value.ToFloat();            break;            case TYPE_STRING:                return *data.value_string >= value.ToString();            break;        }        return false;    }    bool operator<(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int < value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float < value.ToFloat();            break;            case TYPE_STRING:                return *data.value_string < value.ToString();            break;        }        return false;    }    bool operator<=(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int <= value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float <= value.ToFloat();            break;            case TYPE_STRING:                return *data.value_string <= value.ToString();            break;        }        return false;    }    Variable operator*(int value) const {        return ToInt() * value;    }    Variable operator*(float value) const {        return ToFloat() * value;    }    Variable operator*(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int * value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float * value.ToFloat();            break;        }        return *this;    }    Variable operator/(int value) const {        return value != 0 ? Variable(ToInt() / value) : *this;    }    Variable operator/(float value) const {        return value != 0.0f ? Variable(ToFloat() / value) : *this;    }    Variable operator/(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int / value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float / value.ToFloat();            break;        }        return *this;    }    Variable operator-(int value) const {        return ToInt() - value;    }    Variable operator-(float value) const {        return ToFloat() - value;    }    Variable operator-(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int - value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float - value.ToFloat();            break;        }        return *this;    }    Variable operator+(int value) const {        return ToInt() + value;    }    Variable operator+(float value) const {        return ToFloat() + value;    }    Variable operator+(const std::string& value) const {        return ToString() + value;    }    Variable operator+(const char* value) const {        return ToString() + (value == NULL ? "" : value);    }    Variable operator+(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int + value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float + value.ToFloat();            break;            case TYPE_STRING:                return *data.value_string + value.ToString();            break;        }        return *this;    }    Variable& operator*=(int value) {        *this = *this * value;        return *this;    }    Variable& operator*=(float value) {        *this = *this * value;        return *this;    }    Variable& operator*=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int *= value.ToInt();            break;            case TYPE_FLOAT:                data.value_float *= value.ToFloat();            break;        }        return *this;    }    Variable& operator/=(int value) {        *this = *this / value;        return *this;    }    Variable& operator/=(float value) {        *this = *this / value;        return *this;    }    Variable& operator/=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int /= value.ToInt();            break;            case TYPE_FLOAT:                data.value_float /= value.ToFloat();            break;        }        return *this;    }    Variable& operator-=(int value) {        *this = *this - value;        return *this;    }    Variable& operator-=(float value) {        *this = *this - value;        return *this;    }    Variable& operator-=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int -= value.ToInt();            break;            case TYPE_FLOAT:                data.value_float -= value.ToFloat();            break;        }        return *this;    }    Variable& operator+=(int value) {        *this = *this + value;        return *this;    }    Variable& operator+=(float value) {        *this = *this + value;        return *this;    }    Variable& operator+=(const std::string& value) {        *this = *this + value;        return *this;    }    Variable& operator+=(const char* value) {        return *this += std::string(value == NULL ? "" : value);    }    Variable& operator+=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int += value.ToInt();            break;            case TYPE_FLOAT:                data.value_float += value.ToFloat();            break;            case TYPE_STRING:                *data.value_string += value.ToString();            break;        }        return *this;    }    Variable operator<<(int value) const {        return ToInt() << value;    }    Variable operator<<(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int << value.ToInt();            break;        }        return *this;    }    Variable& operator<<=(int value) {        *this = *this << value;        return *this;    }    Variable& operator<<=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int << value.ToInt();            break;        }        return *this;    }    Variable operator>>(int value) const {        return ToInt() >> value;    }    Variable operator>>(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int >> value.ToInt();            break;        }        return *this;    }    Variable& operator>>=(int value) {        *this = *this >> value;        return *this;    }    Variable& operator>>=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int >>= value.ToInt();            break;        }        return *this;    }    Variable operator%(int value) const {        return ToInt() % value;    }    Variable operator%(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int % value.ToInt();            break;        }        return *this;    }    Variable& operator%=(int value) {        *this = *this % value;        return *this;    }    Variable& operator%=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int %= value.ToInt();            break;        }        return *this;    }    Variable operator^(int value) const {        return ToInt() ^ value;    }    Variable operator^(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int ^ value.ToInt();            break;        }        return *this;    }    Variable& operator^=(int value) {        *this = *this ^ value;        return *this;    }    Variable& operator^=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int ^= value.ToInt();            break;        }        return *this;    }    Variable operator&(int value) const {        return ToInt() & value;    }    Variable operator&(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int & value.ToInt();            break;        }        return *this;    }    Variable& operator&=(int value) {        *this = *this & value;        return *this;    }    Variable& operator&=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int &= value.ToInt();            break;        }        return *this;    }    Variable operator|(int value) const {        return ToInt() | value;    }    Variable operator|(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int | value.ToInt();            break;        }        return *this;    }    Variable& operator|=(int value) {        *this = *this | value;        return *this;    }    Variable& operator|=(const Variable& value) {        switch(type)        {            case TYPE_INTEGER:                data.value_int |= value.ToInt();            break;        }        return *this;    }    Variable operator&&(int value) const {        return ToInt() && value;    }    Variable operator&&(float value) const {        return ToFloat() && value;    }    Variable operator&&(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int && value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float && value.ToFloat();            break;        }        return *this;    }    Variable operator||(int value) const {        return ToInt() || value;    }    Variable operator||(float value) const {        return ToFloat() || value;    }    Variable operator||(const Variable& value) const {        switch(type)        {            case TYPE_INTEGER:                return data.value_int || value.ToInt();            break;            case TYPE_FLOAT:                return data.value_float || value.ToFloat();            break;        }        return *this;    }    Variable operator-() const {        switch(type)        {            case TYPE_INTEGER:                return -data.value_int;            break;            case TYPE_FLOAT:                return -data.value_float;            break;        }        return *this;    }    Variable& operator--() {        switch(type)        {            case TYPE_INTEGER:                --data.value_int;            break;            case TYPE_FLOAT:                --data.value_float;            break;        }        return *this;    }    Variable operator--(int) {        switch(type)        {            case TYPE_INTEGER:                data.value_int--;            break;            case TYPE_FLOAT:               data.value_float--;            break;        }        return *this;    }    Variable& operator++() {        switch(type)        {            case TYPE_INTEGER:                ++data.value_int;            break;            case TYPE_FLOAT:                ++data.value_float;            break;        }        return *this;    }    Variable operator++(int) {        switch(type)        {            case TYPE_INTEGER:                data.value_int++;            break;            case TYPE_FLOAT:                data.value_float++;            break;        }        return *this;    }    Variable operator+() const {        switch(type)        {            case TYPE_INTEGER:                return +data.value_int;            break;            case TYPE_FLOAT:                return +data.value_float;            break;        }        return *this;    }    Variable operator!() const {        switch(type)        {            case TYPE_INTEGER:                return !data.value_int;            break;            case TYPE_FLOAT:                return !data.value_float;            break;        }        return *this;    }    Variable operator~() const {        switch(type)        {            case TYPE_INTEGER:                return ~data.value_int;            break;        }        return *this;    }    char& operator[](size_t index) {        return (*data.value_string)[index];    }    const char& operator[](size_t index) const {        return (*data.value_string)[index];    }};#endif // VARIABLEH


NOTE: It's long because it overloads every operator for each data type.

It's a class i made that can act as an int, float or string. It's pretty much like the "typeless" variables they have in other scripting engines. It's different to the "scriptany" class because it's much more natural to use. For example:

Variable myVars[] = {  "Derp",  1234,  1234.5678f};std::string var1 = myVars[0];int var2         = myVars[1];float var3       = myVars[2];


Note the automatic casting both ways. It will even work if you pass "Variable" objects to functions that require int, float or string for parameters.
Yes, it should work. I actually have plans to implement a similar class as a standard add-on myself.

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

So when registering that class, would i use "asOBJ_VALUE" ?
Advertisement
Since you want it to behave similarly to any other primitive type, then yes, asOBJ_VALUE would be the recommended choice.

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

Getting an error when it tries to compile the angelscript module:

Heres the variable class:
void RegisterScriptVariable(asIScriptEngine *engine){    int r = 0;    // Register the type    r = engine->RegisterObjectType("var", sizeof(Variable), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); assert( r >= 0 );    // Register the constructors    r = engine->RegisterObjectBehaviour("var", asBEHAVE_CONSTRUCT,    "void f()",               asFUNCTION(VariableDefaultConstructor), asCALL_CDECL_OBJFIRST); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_CONSTRUCT,    "void f(int)",            asFUNCTION(VariableIntConstructor),     asCALL_CDECL_OBJFIRST); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_CONSTRUCT,    "void f(float)",          asFUNCTION(VariableFloatConstructor),   asCALL_CDECL_OBJFIRST); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_CONSTRUCT,    "void f(const var& in)",  asFUNCTION(VariableCopyConstructor),    asCALL_CDECL_OBJFIRST); assert( r >= 0 );    //Register the destructor    r = engine->RegisterObjectBehaviour("var", asBEHAVE_DESTRUCT,     "void f()",               asFUNCTION(VariableDestructor),         asCALL_CDECL_OBJFIRST); assert( r >= 0 );    //Register the casting (Variable should be able to cast to int, float and string)    r = engine->RegisterObjectBehaviour("var", asBEHAVE_IMPLICIT_VALUE_CAST, "int f()",         asFUNCTION(VariableCastInt),            asCALL_CDECL_OBJFIRST);       assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_IMPLICIT_VALUE_CAST, "float f()",       asFUNCTION(VariableCastFloat),          asCALL_CDECL_OBJFIRST);       assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_IMPLICIT_VALUE_CAST, "string@ f()",     asFUNCTION(VariableCastString),         asCALL_CDECL_OBJFIRST);       assert( r >= 0 );    //Register the assignment operator    r = engine->RegisterObjectBehaviour("var", asBEHAVE_ASSIGNMENT,   "var& f(const var& in)",      asMETHODPR(Variable, operator=, (const Variable&), Variable&),      asCALL_THISCALL); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_ASSIGNMENT,   "var& f(const string& in)",   asMETHODPR(Variable, operator=, (const std::string&), Variable&),   asCALL_THISCALL); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_ASSIGNMENT,   "var& f(int)",                asMETHODPR(Variable, operator=, (int), Variable&),                  asCALL_THISCALL); assert( r >= 0 );    r = engine->RegisterObjectBehaviour("var", asBEHAVE_ASSIGNMENT,   "var& f(float)",              asMETHODPR(Variable, operator=, (float), Variable&),                asCALL_THISCALL); assert( r >= 0 );}


Here's the angelscript module that will not compile. The error happens when it tries to cast from "var" to "string". This script works fine if i try to cast from "var" to "float" or "int".

//#Server core script (REQUIRED)var derp = "blah";void main(){  string test = derp;  Print(test);}


Here's the error:
Loading plugins... (6, 1) : INFO : Compiling void main() (8, 17) : ERR  : Found more than one matching operatorUnable to load plugin: Server


EDIT: Another problem. This returns an error (-7)
r = engine->RegisterObjectBehaviour("var", asBEHAVE_IMPLICIT_VALUE_CAST, "bool f()",        asFUNCTION(VariableCastBool),           asCALL_CDECL_OBJFIRST);


I wanted to register the bool operator so i could do:

var myVar = 1;if(myVar){}


That script doesn't work :(

[Edited by - 39ster on April 16, 2009 12:47:54 AM]
By design AngelScript doesn't allow conversions to or from the boolean type (it is a very common cause for bugs with novice programmers). For that reason it also doesn't support registering the cast operator to bool.

I'll have to investigate the compilation error for assigning the var type to the string type. The compiler really should have listed the operators it found so that it would have been easier to understand.

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