Author Topic: Broken bricks that cost money?  (Read 1606 times)

Since i installed some addons. got this error

$joinScore=100;
$brickCost=1;
$setScoreOnEnter=1;



package payToPlantBricks {
function fxDTSbrick::onPlant(%this) {
Parent::onPlant(%this);
%client = %this.getGroup().client;
if(%client.score > %brickCost-1) {
%client.score = %client.score - %brickCost;
commandToClient(%client, 'bottomPrint', "\c2You have paid 1 score point to plant this brick.", 1);
} else {
commandToClient(%client, 'centerPrint', "You have no more score to plant a brick.", 3);
%this.schedule(0,"delete");
}
}
function GameConnection::autoAdminCheck(%client){
Parent::autoAdminCheck(%client);
if($setScoreOnEnter == 1) {
%client.setScore($joinScore);
}
}
};
activatePackage(payToPlantBricks);

It doesnt steal my  points anymore.

Can't edit post. but this is fixed one

Code: [Select]
$joinScore=100;
$brickCost=1;
$setScoreOnEnter=1;



package payToPlantBricks {
function fxDTSbrick::onPlant(%this) {
Parent::onPlant(%this);
%client = %this.getGroup().client;
if(%client.score > %brickCost-1) {
%client.score = %client.score - %brickCost;
commandToClient(%client, 'bottomPrint', "\c2You have paid 1 score point to plant this brick.", 1);
} else {
commandToClient(%client, 'centerPrint', "You have no more score to plant a brick.", 3);
%this.schedule(0,"delete");
}
}
function GameConnection::autoAdminCheck(%client){
Parent::autoAdminCheck(%client);
if($setScoreOnEnter == 1) {
%client.setScore($joinScore);
}
}
};
activatePackage(payToPlantBricks);

It doesnt steal my points anymore.Why?

Bump, i'm trying to fix this by myself.

%client.score = %client.score - %brickCost;
should be
%client.score = %client.score - $brickCost;
note the change of % to $, since $brickCost is a global variable and not a local one

%client.score = %client.score - %brickCost;
should be
%client.score = %client.score - $brickCost;
note the change of % to $, since $brickCost is a global variable and not a local one

Doesn't seem to fix it.

Doesn't seem to fix it.

NVM i fixed it by myself. thanks anyways for telling me the variables.

Badspot

  • Administrator
NVM i fixed it by myself. thanks anyways for telling me the variables.

Post the solution.

what is broken about the code besides the %/$ difference?
it looks like it should work

Since he claimed it fixed itself, I'm going to go ahead and re-solve this.

Original code (formatted for easier reading):
Code: [Select]
$joinScore=100;
$brickCost=1;
$setScoreOnEnter=1;

package payToPlantBricks
{
function fxDTSbrick::onPlant(%this)
{
Parent::onPlant(%this);
%client = %this.getGroup().client;
if(%client.score > %brickCost-1)
{
%client.score = %client.score - %brickCost;
commandToClient(%client, 'bottomPrint', "\c2You have paid 1 score point to plant this brick.", 1);
}
else
{
commandToClient(%client, 'centerPrint', "You have no more score to plant a brick.", 3);
%this.schedule(0,"delete");
}
}
function GameConnection::autoAdminCheck(%client)
{
Parent::autoAdminCheck(%client);
if($setScoreOnEnter == 1)
{
%client.setScore($joinScore);
}
}
};
activatePackage(payToPlantBricks);

Problem 1: Line 11
%brickCost is never defined. I imagine they wanted to use $brickCost instead.
if(%client.score > $brickCost-1) would be if(score > cost-1 (0)), it would be more logical to use if(score >= cost (1)).
Solution 1:
      if(%client.score >= $brickCost)

Problem 2: Line 13
%brickCost is never defined. Use $brickCost instead.
You could also use %client.score-=x; instead of %client.score = %client.score - x;
Solution 2:
         %client.score-=$brickCost;


Other things that could be improved:
Line 14:
The command just tells the client they paid 1, even though $brickCost does not have to be 1.
Solution:
         commandToClient(%client, 'bottomPrint', "\c2You have paid " @ $brickCost @ " points to plant this brick.", 1);
This will display the cost of the brick instead.

Other than that, it should work fine.

Forgot to post the new code:
Code: [Select]
$joinScore=100;
$brickCost=1;
$setScoreOnEnter=1;

package payToPlantBricks
{
function fxDTSbrick::onPlant(%this)
{
Parent::onPlant(%this);
%client = %this.getGroup().client;
if(%client.score >= $brickCost)
{
%client.score-=$brickCost;
commandToClient(%client, 'bottomPrint', "\c2You have paid " @ $brickCost @ " points to plant this brick.", 1);
}
else
{
commandToClient(%client, 'centerPrint', "You have no more score to plant a brick.", 3);
%this.schedule(0,"delete");
}
}
function GameConnection::autoAdminCheck(%client)
{
Parent::autoAdminCheck(%client);
if($setScoreOnEnter == 1)
{
%client.setScore($joinScore);
}
}
};
activatePackage(payToPlantBricks);

Ok, so I made a few mistakes. I should proof-read before posting code and score > brickcost-1 is the same as score >= brickcost. I just find it easier to understand like that.

score > brickcost-1 is the same as score >= brickcost. I just find it easier to understand like that.
It's not the same.

0.1 > 1-1 = true
0.1 >= 1 = false

Also, had no idea you were OP.

Why would anyone have decimals in their score?

Why would anyone have decimals in their score?
In almost all cases, they don't.

But it's better practice to use the right tool for the job, especially because there will be cases where it's needed.