[ZScript] Recursively returning multiple values

Fri Dec 21, 2018 2:15 am

It looks like the ZScript VM cannot recursively return multiple values from a function that returns multiple values. For example, switching to the next or previous weapon while there is a pending weapon does not work as expected. The real issue seems to be in zscript/shared/player.txt on line 1927.

Apparently, this works properly:
Code:
if (player.PendingWeapon != WP_NOCHANGE)
{
   bool found;
   int slot;
   int index;
   [found, slot, index] = player.weapons.LocateWeapon(player.PendingWeapon.GetClass());
   return found, slot, index;
}


But this code, which is currently being used, does not:
Code:
if (player.PendingWeapon != WP_NOCHANGE)
{
   return player.weapons.LocateWeapon(player.PendingWeapon.GetClass());
}


Note that I am NOT using the JIT compiler, as I don't quite trust it to be stable enough for everyday use yet.

Re: [ZScript] Recursively returning multiple values

Fri Dec 21, 2018 4:15 am

This was already reported here.

Re: [ZScript] Recursively returning multiple values

Fri Dec 21, 2018 4:46 am

This one's more descriptiv, though. However, since I currently have no idea how to handle this, I changed the problem code to use the above workaround.

Re: [ZScript] Recursively returning multiple values

Fri Dec 21, 2018 5:08 am

But this won't prevent usage of the same broken code in mods. Fixing core script without prohibiting re-return of multiple values seems a bit fragile.

Re: [ZScript] Recursively returning multiple values

Fri Dec 21, 2018 5:12 am

I know, but the last time a fix was attempted it didn't work out. The report needs to remain open but that alone is no reason to leave the non-functional code in.