Author Topic: NewTimer - wrong number of parameters  (Read 2822 times)

MarcinBBlack

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-3
    • View Profile
NewTimer - wrong number of parameters
« on: June 29, 2017, 01:08:08 am »
Hi,
for last few days I've been struggling with calling my function through NewTimer. In the result server throws the following error message : "An error has occured [wrong number of parameters]
CALLSTACK
LOCALS".

Looks like my passed argument  'playerTeam' is treated as null (its instance of DominationTeam class), however printing 'playerTeam.Score' outside of timer shows that there is value indeed.

I tried also to pass just simply number and increase it. In that case there is no error like that, but I guess the variable is passed by value so only copy of it is taken to the function (it prints 1 at every timer tick).

Another way I tried is to create score variable with bigger scope than just function. In this solution no error is thrown, but Message(score) called after incrementing the score value showed nothing. 

I really don't have idea what Im doing wrong, so an help will be greatly appreciated ;).

Below I put the code, onPlayerEnterCheckpoint method  is the place where issue happens.

Code: [Select]
   
    local RED = Colour(255,0,0);
    local BLUE = Colour(0,0,255);
    local WHITE = Colour(255,255,255);
//
class DominationTeam
{
      Name = null;
TeamColour = WHITE;
Score = 0;
   constructor(colorOfTheTeam)
   {
Score = 0;
if(colorOfTheTeam == RED || colorOfTheTeam == BLUE)
TeamColour = colorOfTheTeam ;
Name = colorOfTheTeam == RED ? "Red" : "Blue";
   }
}
//
local redTeam = DominationTeam(RED);
local blueTeam = DominationTeam(BLUE);
local domPointBlip = null;
local scoreTimer = null;
//
function onPlayerSpawn(player,spawn)
{
   local playerCount = GetPlayerCount();
   player.Team = playerCount % 2 == 0 ? 1 : 0 ;
}

function onPlayerCommand(player,cmd,text)
{
      if (cmd == "domination")
{
local playerPos = player.Pos;
local checkpointPos = Vector(playerPos.x + 5, playerPos.y + 5, playerPos.z);
CreateCheckpoint(checkpointPos,2.0, WHITE);
domPointBlip = CreateBlip(BLIP_NONE, checkpointPos);
domPointBlip.Colour = WHITE;
Message("Domination begins!");
     }
}

 function SetTeamScore(team)
{
   team.Score+=1;
   ::print(team.Score);
}

function onPlayerEnterCheckpoint(player, cp)
{
local playerTeamId = player.Team;
cp.Colour = playerTeamId == 0 ? RED : BLUE ;
domPointBlip.Colour = playerTeamId == 0 ? 0 : 1;
local playerTeam = playerTeamId == 0 ? redTeam : blueTeam;
Message(playerTeam.Name + " " + playerTeam.Score);
    NewTimer("SetTeamScore", 3000, 5, playerTeam);
   
}


« Last Edit: June 29, 2017, 01:11:10 am by MarcinBBlack »

MarcinBBlack

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-3
    • View Profile
Re: NewTimer - wrong number of parameters
« Reply #1 on: July 06, 2017, 12:29:54 am »
Ok so the problem was with passing class instance member to function invoked in timer. I resolved it by passing teamId and increasing red or blue team score based on that.
« Last Edit: June 08, 2024, 12:49:39 am by SugarD »

 

© Liberty Unleashed Team.