I'm actually having this issue on LU, but I was advised to ask here since we couldn't figure it out.
So I'm creating this minigame script, and at the end of each minigame, every participating player gets paid a certain amount of money depending on how well they played (0.8x of what the previous player got).
Edit, pastebin'd for better readabilty: https://pastebin.com/y0Rn3Fnm
So this code works, until you uncomment the _player.Cash += _payout; line. Then only the first iteration will succeed, and it will error on the second one. For some reason when that line is uncommented, _player is set to the player ID(int), instead of a Player reference.
Here's testing with that line commented out, and some debug prints. All works fine:
However, when I uncomment the _player.Cash += _payout; line, this is what I get:
So can anyone tell if there is something wrong with my code? Or have a run into an unfortunate LU bug?
Hoping someone can help
So I'm creating this minigame script, and at the end of each minigame, every participating player gets paid a certain amount of money depending on how well they played (0.8x of what the previous player got).
Edit, pastebin'd for better readabilty: https://pastebin.com/y0Rn3Fnm
Code Select
function payoutPlayers(){
local topArray = [];
foreach(id, score in playerScores){
if(score > 0){
topArray.push({id = id, score = score});
}
}
topArray.sort(sortScores);
local _payout = currentMinigame.payout;
foreach(pos, scoreinfo in topArray){
local _player = FindPlayer(scoreinfo.id);
if(_player){
local realpos = pos + 1;
//_player.Cash += _payout;
BigMessage(_player, "You came " + realpos + " in the " + currentMinigame.name, 5000, 3);
_payout = abs(_payout * 0.8);
}
_player = null;
}
}
So this code works, until you uncomment the _player.Cash += _payout; line. Then only the first iteration will succeed, and it will error on the second one. For some reason when that line is uncommented, _player is set to the player ID(int), instead of a Player reference.
Here's testing with that line commented out, and some debug prints. All works fine:
Code Select
SCRIPT: before if(_player): Theremin
SCRIPT: before _player.Cash: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before BigMessage: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before if(_player): Rhytz
SCRIPT: before _player.Cash: Rhytz
SCRIPT: Cash: 4054 _player: Rhytz(Player)pos: 2 payout: 12000(integer)
SCRIPT: before BigMessage: Rhytz
SCRIPT: Cash: 4054 _player: Rhytz(Player)pos: 2 payout: 12000(integer)
SCRIPT: [lu-minigames] Minigame ended
However, when I uncomment the _player.Cash += _payout; line, this is what I get:
Code Select
SCRIPT: before if(_player): Theremin
SCRIPT: before _player.Cash: Theremin
SCRIPT: Cash: 18005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before BigMessage: Theremin
SCRIPT: Cash: 33005 _player: Theremin(Player)pos: 1 payout: 15000(integer)
SCRIPT: before if(_player): 1
SCRIPT: before _player.Cash: 1
AN ERROR HAS OCCURED [the index 'Cash' does not exist]
CALLSTACK
*FUNCTION [payoutPlayers()] Scripts/lu-minigames/main_s.nut line [164]
*FUNCTION [stopMinigame()] Scripts/lu-minigames/main_s.nut line [141]
LOCALS
[playerScores] ARRAY
[currentMinigame] TABLE
[realpos] 2
[_player] 1
[@ITERATOR@] 2
[scoreinfo] TABLE
[pos] 1
[_payout] 12000
[topArray] ARRAY
[this] TABLE
[minigameState] "ended"
[eligiblePlayers] TABLE
[currentMinigame] TABLE
[this] TABLE
So can anyone tell if there is something wrong with my code? Or have a run into an unfortunate LU bug?
Hoping someone can help