TakeDamage can only give 0.5 hearts
#1
Currently the cPawn:TakeDamage can only damage a entity by 0.5 hearts. could that maybe be improved that you can do TakeDamage(Player, 2)?
Reply
Thanks given by:
#2
Which of the three functions are you using? In C++ there are these declarations (all exported to Lua):
Code:
/// Makes this pawn take damage from an attack by a_Attacker. Damage values are calculated automatically and DoTakeDamage() called
void TakeDamage(cPawn & a_Attacker);

/// Makes this pawn take the specified damage. The final damage is calculated using current armor, then DoTakeDamage() called
void TakeDamage(eDamageType a_DamageType, cPawn * a_Attacker, int a_RawDamage, double a_KnockbackAmount);

/// Makes this pawn take the specified damage. The values are packed into a TDI, knockback calculated, then sent through DoTakeDamage()
void TakeDamage(eDamageType a_DamageType, cPawn * a_Attacker, int a_RawDamage, int a_FinalDamage, double a_KnockbackAmount);
So I think something like TakeDamage(dtEnvironment, nil, 4, 0); should call the middle variant, giving 2 hearts of environmental damage with zero knockback.
Reply
Thanks given by:
#3
how to call functions with another name? :O
Reply
Thanks given by:
#4
I don't understand the question.

To call one of those functions, you need to supply the correct number and types of parameters. Once you do, Lua will automagically call the correct function, even when the names are the same. C++ has the same feature, it's called function overloading.
Reply
Thanks given by:
#5
i tried TakeDamage(dtEnvironment, nil, 4, 0) but it says: argument #2 is 'nil'; 'value' expected.
Reply
Thanks given by:
#6
I don't think overloading actually works with the automatically generated bind code from tolua.
You'd have to bind the functions yourself and analyse the arguments to call the correct function.
Reply
Thanks given by:
#7
Tolua docs say overloading works, and the generated glue code seems like it should work. Only I guess it doesn't work properly with nil values.

Anyway, we could cook up a few synonyms for the needed functions, such as TakeEnvironmentalDamage(Amount, Knockback)
Reply
Thanks given by:
#8
How CAN tolua work with overloaded functions?
We use the exact same method of binding the functions manually and we DO have to analyse the parameter types ourselves.

For example I see there are two cEntity::AddPosition overloads exported to tolua. They are registered like this:
Code:
tolua_function(tolua_S,"AddPosition",tolua_AllToLua_cEntity_AddPosition00);
tolua_function(tolua_S,"AddPosition",tolua_AllToLua_cEntity_AddPosition01);

No extra information has been given about the signature of the function so it cannot be handled by "tolua_function" itself. However two different function pointers are now bound to the same function name.
I do not know for sure, but I suspect the last statement just overwrites the first one, or the last one is ignored because the function is already registered.

tolua_AllToLua_cEntity_AddPosition00/01 are already specialized for their overloaded counterparts so there is no actual overloading done in there, they can only call one C++ function.

Either we're doing something wrong, or tolua does not really support overloading functions
Reply
Thanks given by:
#9
Have a look at the tolua_AllToLua_cEntity_AddPosition01() function. It knows it is overloaded, so if its parameters don't match, instead of calling the error function, it hands off to tolua_AllToLua_cEntity_AddPosition00(), thus forming the chain. Runtime overloads, yay for speedTongue
Reply
Thanks given by:
#10
Ohhhh you're right, I feel so silly now. I only looked in the 00 function not the 01.. Sad
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)