[Bug][IW5] ChaiScript Unable to unbox value of type 'unsigned int'
-
How to replicate bug:
global secondary = ["emp_grenade_mp", "flare_mp", "flash_grenade_mp", "concussion_grenade_mp", "trophy_mp"]; var secondaryLength = secondary.size(); var a2 = gsc.randomInt(secondaryLength);
Output:
******* Script execution error ******* Unable to unbox value of type 'unsigned int' **************************************
gsc.randomInt(int max); works well when using any other number that does not come from the function .size().
According to documents I found online global variable "secondary" is a vector and the function size should return the number of elements inside the vector.
For some reason this sequence of code breaks. The number that is returned from the function size() can be used for anything else but I simply cannot call gsc functions from what I can gather.
Unfortunately, I can't tell if this is chai script bug or a pluto bug.
Any advice is greatly appreciated. -
Try something like
var secondaryLength = 0 + secondary.size();
-
Xerxes Triggers the same error.
var secondaryLength = 0 + secondary.size(); var a1 = gsc.randomInt(gunListLength);
Also tried multiplying by 1 but it appears chai script doesn't forget it's dealing with an unsigned int.
I will try to look on their Github issue tracker to see if it could be something on their end but I'm afraid it's pluto bug because I would not expect their built-in data structure to cause bugs when attempting to do simple things like this.
As a work around (and because chai script doesn't expose rand()), I have found a simple random number generator online:def myRandom(max) { var seed = gsc.getTime(); var a = 1103515245; var c = 12345; var m = 2147483648; seed = (a * seed + c) % m; seed = seed % max; print("Return random number " + to_string(seed)); return seed; }
That is my workaround, but for obvious reasons, the randomness is very wack and when I call it from the same function gsc.getTime(); returns the same seed since it can only return multiples of 50.
It would be great if one on the devs could look at unboxing unsigned integers. -
Mr. Android Hello, I hope my tag finds you well.
I believe I have located the root of the problem.
https://github.com/momo5502/open-iw5/blob/master/src/game/scripting/parameters.cpp#L98It seems there is no possibility under the current implementation of chai to use unsigned integers as parameters for game functions because there is no code to unbox them and send them to game functions. I hope this will be considered in a future Pluto release because the vector ds is a chai script feature and while it's unfortunate their .size() function returns a uint I think it should be supported.
Thanks. -
Use to_int()
-
me who just randomly stumbled upon this:
-
fed I'll accept your solution as a valid workaround. Thank you very much.
Waiting for one of the devs to acknowledge the bug anyway since the underline issue stays.