Advertisement

What to use if I wan to send a negative value to a script function?

Started by May 29, 2012 03:24 PM
2 comments, last by WitchLord 12 years, 6 months ago
What the title says.... The manual mentions:


[color=#604020]int SetArgDWord([color=#604020]int arg, asDWORD value);
[color=#604020]int SetArgQWord([color=#604020]int arg, asQWORD value);
[color=#604020]int SetArgFloat([color=#604020]int arg, [color=#604020]float value);
[color=#604020]int SetArgDouble([color=#604020]int arg, [color=#604020]double value);
[color=#604020]int SetArgByte([color=#604020]int arg, asBYTE value);
[color=#604020]int SetArgWord([color=#604020]int arg, asWORD value);

But all values are of unsigned type! How can I send a "-1" to my script?

Thanks.

Carlos
SetArgDWord(0, asDWORD(-1));

alternatively

*reinterpret_cast<int*>*(GetAddressOfArg(0)) = -1;


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

Advertisement
So the negative value is reinterpreted as an unsigned value, and then again when inside the script reinterpreted as a signed int, restoring the original value?
Yes. The Byte, Word, DWord, and QWord versions are just to get the right size of the data. It doesn't matter whether the information is signed or not.

I would have used the DWord and QWord for float and doubles too, had it not been for the complications of transforming the values without changing the binary representation. I guess a reinterpret_cast would solve that, but I didn't want to force the application developer to go through that.

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