Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Donate
Collapse

Plutonium

  1. Home
  2. MW3 Modding Support & Discussion
  3. [Bug][IW5] ChaiScript Unable to unbox value of type 'unsigned int'

[Bug][IW5] ChaiScript Unable to unbox value of type 'unsigned int'

Scheduled Pinned Locked Moved MW3 Modding Support & Discussion
7 Posts 4 Posters 418 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FutureRaveundefined Offline
    FutureRaveundefined Offline
    FutureRave VIP
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Xerxesundefined Offline
      Xerxesundefined Offline
      Xerxes Plutonium Staff
      wrote on last edited by
      #2

      Try something like

      var secondaryLength = 0 + secondary.size();

      FutureRaveundefined 1 Reply Last reply
      0
      • FutureRaveundefined Offline
        FutureRaveundefined Offline
        FutureRave VIP
        replied to Xerxes on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • FutureRaveundefined Offline
          FutureRaveundefined Offline
          FutureRave VIP
          wrote on last edited by FutureRave
          #4

          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#L98

          It 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.

          1 Reply Last reply
          0
          • fedundefined Offline
            fedundefined Offline
            fed
            wrote on last edited by
            #5

            Use to_int()

            FutureRaveundefined 1 Reply Last reply
            0
            • Ace_rinundefined Offline
              Ace_rinundefined Offline
              Ace_rin
              wrote on last edited by
              #6

              me who just randomly stumbled upon this:😵

              1 Reply Last reply
              0
              • FutureRaveundefined Offline
                FutureRaveundefined Offline
                FutureRave VIP
                replied to fed on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Donate