Author Topic: Script Won't Change Brick  (Read 1022 times)

I'm trying to get a brick to change states when activated, but when I try it ingame, the brick won't switch, but it makes a sound.

Code: [Select]
datablock fxDTSBrickData(mugfulldata)
{
brickFile = "./mugfull.blb";
category = "special";
subCategory = "misc";
uiName = "Coffee Mug";
iconName = "Add-Ons/Brick_MarcemOddsEnds/mug";
};

datablock fxDTSBrickData(mugemptydata)
{
brickFile = "./mugempty.blb";
category = "";
subCategory = "";
uiName = "Coffee Mug";
iconName = "";
};

function drinkCoffee(%obj)
{
        %obj.setDataBlock("mugemptydata");
}

function fillCoffee(%obj)
{
%obj.setDataBlock("mugfulldata");
}
package coffeeDrink
{   
   function fxDTSBrick::OnActivate(%obj, %player, %client, %pos, %vec)
     {
       if(%obj.getDataBlock().getName() $= "mugfullData")
            drinkCoffee(%obj);
       if(%obj.getDataBlock().getName() $= "mugemptyData")
            fillCoffee(%obj);
       parent::OnActivate(%obj, %player, %client, %pos, %vec);
     }
};
activatePackage(coffeeDrink);

What exactly am I doing wrong here?
« Last Edit: December 04, 2011, 02:05:06 AM by Marcem »

There needs to be a semicolon  (this thing ; ) at the end of parent::OnActivate(%obj, %player, %client, %pos, %vec)

Always look one line above the error if you don't see anything in the line it says.

Oh!  Thanks, never noticed that.
Now I'm having an issue with the actual brick not changing when activated.
« Last Edit: December 03, 2011, 02:24:19 PM by Marcem »

Did you look at the default treasure chest brick to see how to do it?

I was going off of the pumpkin brick

Changed thread for help with changing states.

Base your script off the treasure chest instead of the pumpkin. It should be as easy as copying the code and then just editing it.

Actually, the treasure chest goes through a bunch of checks before actually switching the datablock.

Whatever, did it now, it's working.
« Last Edit: December 04, 2011, 05:30:30 PM by Marcem »

Make it pourCoffee instead of fillCoffee.

Make it pourCoffee instead of fillCoffee.
Why?  I don't have the function in there anymore anyway.

because the two if statements fire one after the other, it will empty the mug then instantly refill it. add an else:
Code: [Select]
package coffeeDrink
{   
   function fxDTSBrick::OnActivate(%obj, %player, %client, %pos, %vec)
   {
      %n = %obj.getDatablock().getName();
      if(%n $= "mugfullData")
      {
         %obj.setDatablock(mugEmptyData);
         if(getRandom(0,20) == 13 && isObject(%player.client))
            messageClient(%player.client,'',"\c3javajavajavajavajavajavajavajavajavajava");

      } else if(%n $= "mugEmptyData")
      {
         %obj.setDatablock(mugFullData);
      }
      parent::OnActivate(%obj, %player, %client, %pos, %vec);
   }
};
activatePackage(coffeeDrink);
disregard easter egg it does not exist

Ah, thanks.  I guess I should lock this now that the issue is fixed twice.