Author Topic: Parent Delay  (Read 1083 times)

Code: [Select]
package hasLight{
function serverCmdLight(%client){
if(!%client.hasLight){
%client.hasLight = true;
}
else{
%client.hasLight = false;
}
schedule(5000,0,parent::serverCmdLight(%client));
}
};
activatePackage(hasLight);
So basically this code detects whether or not a player has their light out..
what I'm TRYING to make it do is have a 5 second delay so that it takes
5 seconds to turn it on/off. For some reason that won't work... how can
I fix this? Also, do I need my own code to detect players' lights? I feel like
there was already some code written in for that. If so, what is it?

I'm sure there's a less wonky way to do this, but one way would be to schedule eval:

Code: [Select]
%code = "parent::serverCmdLight(%client);";
schedule(5000, 0, eval, code);

OH, I just now realized what you did wrong. In a schedule the arguments go in the following arguments, so it would be
Code: [Select]
schedule(5000, 0, parent::serverCmdLight, %client);

You can't schedule a call to the parent. You'll have to make a schedule to call the function itself with an extra parameter that makes it call the parent.

Ok, so I did
Code: [Select]
package hasLight{
function serverCmdLight(%client){
if(!%client.hasLight){
%client.hasLight = true;
}
else{
%client.hasLight = false;
}
schedule(5000,0,lightParent,%client);
}
};
activatePackage(hasLight);

function lightParent(%client){
parent::serverCmdLight(%client);
}
It delays the 5 seconds but in the console it's saying that the serverCmdLight function doesn't exist.

Code: [Select]
OH! silly me! I had forgotten to put the function inside of the package... also I added
the light detector to the other function.
[code]
package hasLight{
function serverCmdLight(%client){
schedule(5000,0,lightParent,%client);
}
function lightParent(%client){
if(!%client.hasLight){
%client.hasLight = true;
}
else{
%client.hasLight = false;
}
parent::serverCmdLight(%client);
}
};
activatePackage(hasLight);
now... how would I make it so that they can't spam the light button and mess it up?

EDIT: Oh, nvm. I discovered the wonders of sim time[/code]
« Last Edit: January 18, 2016, 08:51:36 PM by Radíowave »

Code: [Select]
OH! silly me! I had forgotten to put the function inside of the package... also I added
the light detector to the other function.
[code]
package hasLight{
function serverCmdLight(%client){
schedule(5000,0,lightParent,%client);
}
function lightParent(%client){
if(!%client.hasLight){
%client.hasLight = true;
}
else{
%client.hasLight = false;
}
parent::serverCmdLight(%client);
}
};
activatePackage(hasLight);
now... how would I make it so that they can't spam the light button and mess it up?

EDIT: Oh, nvm. I discovered the wonders of sim time[/code]
That doesn't look like it would work. Did you test that in-game?

I suggest a few well-placed return;s in the if and else statement. Looks like this might accidentally spam itself

That doesn't look like it would work. Did you test that in-game?

It should work because of the way packaged functions are parented together.

Calling parent::stuff from inside a package that also contains stuff will run the one that is one level above the package.
The parent:: part is not per function, it means go one package level higher.