Author Topic: [Solved] Strange Packaging Bug  (Read 851 times)

I'm encountering a bug where a package is activated during exec and then in-game the code inside the package doesn't work. Then when I deActivatePackage and activatePackage again through the console, it works perfectly.

Anyone run into this before?

Here is the package:
Code: [Select]
package FoodMenu
{
      function Armor::onTrigger(%this, %player, %slot, %val)
      {
         if(isObject(%player.getMountedImage(0)) && %player.getMountedImage(0).getName()$="rawFoodBagImage")
{
   if(%slot == 4 && %val)
   {
      if(%player.client.maxRawFoodOptions $= 1)
 return;

      if(%player.client.currRawFoodSelection $= %player.client.lastRawFoodItem)
      {
    for(%i = 1; 21 > %i; %i++)
                  {
           if(%player.client.rawFood[%i] != 0)
           {
%player.client.currRawFoodSelection = %i;
break;
           }
 }
 %player.playThread(0,plant);
 updateRawFoodUI(%player.client);
 return;
      }

      else
      {
         %player.client.currRawFoodSelection = nextAvailableRawFoodSelection(%player.client);
         %player.playThread(0,plant);
 updateRawFoodUI(%player.client);
         return;
      }
   }
   updateRawFoodUI(%player.client);
}
else Parent::onTrigger(%this, %player, %slot, %val);
      }
};
activatePackage(FoodMenu);

And the function called within:
Code: [Select]
function updateRawFoodUI(%client)
{
   %client.maxRawFoodOptions = getMaxRawFoodOptions(%client);

   %firstTime = 1;
   %foodCount = 0;

   for(%i = %client.currRawFoodSelection; 21 > %i; %i++) //cycle through the player owned foods to create the list
   {
      if(%firstTime)
      {
         %list = "\c6" @ getRawFoodItem(%i) SPC "x" SPC %client.rawFood[%i] @ "\n";
         %foodCount++;
%firstTime = 0;
continue;
      }

      if(%foodCount $= 3) //stop once we have 3 items for the current list
         break;

      %foodItem = %client.rawFood[%i];

      if(%foodItem !$= 0) //if the player has the food, add it to the list
      {
         %list = %list @ "\c7" @ getRawFoodItem(%i) SPC "x" SPC %client.rawFood[%i] @ "\n";
         %foodCount++;
%client.lastRawFoodItem = %i;
      }
   }

   if(%client.maxRawFoodOptions == 1 && %foodCount == 1) //if they have 1 item, don't show the scroll option
   {
      commandToClient(%client,'centerPrint',"<font:impact:64>\c3Raw Food\n<font:impact:32>\c6" @ %list,-1);
      return;
   }

   if(%foodCount $= 0 || %client.maxRawFoodOptions == 0) //no raw food
      commandToClient(%client,'centerPrint',"<font:impact:64>\c3Raw Food\n<font:impact:32>\n\c6You have no raw food packed in your bag.",-1);

   if(%foodCount $= 1 && %client.maxRawFoodOptions > 1) //they're at the end of the list but have more options in the list
      commandToClient(%client,'centerPrint',"<font:impact:64>\c3Raw Food\n<font:impact:32>\c6" @ %list @ "\n\n\c0\\/ \c6Right click to scroll",-1);

   if(%foodCount $= 2) //special case to make sure the scroll UI isn't higher up when there's less options
      commandToClient(%client,'centerPrint',"<font:impact:64>\c3Raw Food\n<font:impact:32>\c6" @ %list @ "\n\c0\\/ \c6Right click to scroll",-1);

   if(%foodCount $= 3) //standard UI
      commandToClient(%client,'centerPrint',"<font:impact:64>\c3Raw Food\n<font:impact:32>\c6" @ %list @ "\c0\\/ \c6Right click to scroll",-1);      
}
« Last Edit: June 01, 2016, 07:27:28 PM by Jervan »

Another package may be overriding Armor::onTrigger and is being activated after your package.
So when you deactivate and reactivate, yours takes priority.

Would this mean I have to consolidate all of the armor::onTrigger packages or just that one is not working properly?

You may want to figure out which package isn't calling the parent.

Ah the old search for the package that contains a function that does not do a Parent.
Also, if you are using returns anyway, you can just put one parent call at the end of the function so that you do not need to add an else with that at every if inside.
Makes your life a lot easier.

just run a trace to test armor ontrigger and see which package it stops at

just run a trace to test armor ontrigger and see which package it stops at
I did not even think of that.
A logical solution.