Author Topic: Code will not add the swatch onto the gui  (Read 768 times)

Yea, I am not sure how it isn't.. The object does exist, the functions work. I just have no idea what is going on.

   function uRPGTabs_Shop_ItemSet::AddShopItem(%this,%image,%name,%cost,%description)
   {
      if(%image $= "")
         %image = "base/client/ui/brickicons/Unknown";
      %strName = strReplace(%name," ","_");
      if(isObject("uRPGShopItem_" @ %strName))
         return;
      if(%image.doColorShift == 1)
      {
         %csc = %image.colorShiftColor;
         %color = mFloatLength((getWord(%csc,0) * 255),0)
            SPC mFloatLength((getWord(%csc,1) * 255),0)
            SPC mFloatLength((getWord(%csc,2) * 255),0)
            SPC mFloatLength((getWord(%csc,3) * 255),0);
      }
      else
         %color = "255 255 255 255";
      %object = new GuiSwatchCtrl("uRPGShopItem_" @ %strName)
      {
         profile = "GuiDefaultProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "188 171";
         extent = "272" SPC getWord(uRPGTabs_Shop_ItemSet.extent,1);
         minExtent = "8 2";
         enabled = "1";
         visible = "1";
         clipToParent = "1";
         color = "0 0 0 100";

         new GuiBitmapCtrl("uRPGShopItem_Picture_" @ %strName)
         {
            profile = "GuiDefaultProfile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "0 0";
            extent = "100 100";
            minExtent = "8 2";
            enabled = "1";
            visible = "1";
            clipToParent = "1";
            wrap = "0";
            lockAspectRatio = "0";
            alignLeft = "0";
            alignTop = "0";
            overflowImage = "0";
            bitmap = %image.iconName;
            keepCached = "0";
            mColor = %color;
            mMultiply = "0";
         };
         new GuiMLTextCtrl("uRPGShopItem_Name_" @ %strName)
         {
            profile = "BlockChatChannelSize3Profile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "105 0";
            extent = "149 22";
            minExtent = "8 2";
            enabled = "1";
            visible = "1";
            clipToParent = "1";
            lineSpacing = "2";
            allowColorChars = "0";
            maxChars = "-1";
            text = "<just:center>" @ %name;
            maxBitmapHeight = "-1";
            selectable = "1";
            autoResize = "1";
         };
         new GuiMLTextCtrl("uRPGShopItem_Cost_" @ %strName)
         {
            profile = "BlockChatChannelSize3Profile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "105 40";
            extent = "149 22";
            minExtent = "8 2";
            enabled = "1";
            visible = "1";
            clipToParent = "1";
            lineSpacing = "2";
            allowColorChars = "0";
            maxChars = "-1";
            text = "<just:center>Cost: " @ %cost @ " Gold";
            maxBitmapHeight = "-1";
            selectable = "1";
            autoResize = "1";
         };
         new GuiMLTextCtrl("uRPGShopItem_Description_" @ %strName)
         {
            profile = "BlockChatChannelSize3Profile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "105 70";
            extent = "150 62";
            minExtent = "150 62";
            enabled = "1";
            visible = "1";
            clipToParent = "1";
            lineSpacing = "2";
            allowColorChars = "0";
            maxChars = "-1";
            text = "<just:center>" @ %description;
            maxBitmapHeight = "-1";
            selectable = "1";
            autoResize = "1";
         };
         new GuiBitmapButtonCtrl("uRPGShopItem_Buy_" @ %strName)
         {
            profile = "BlockButtonProfile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "0 108";
            extent = "100 22";
            minExtent = "8 2";
            enabled = "1";
            command = "commandToServer(\'uRPG_Buy\'," @ %name @ ");";
            visible = "1";
            clipToParent = "1";
            text = "Buy";
            groupNum = "-1";
            buttonType = "PushButton";
            bitmap = "base/client/ui/button1";
            lockAspectRatio = "0";
            alignLeft = "0";
            alignTop = "0";
            overflowImage = "0";
            mKeepCached = "0";
            mColor = "255 255 255 255";
         };
      };
      uRPGTabs_Shop_ItemSet.add(%object);
      %object.setVisible(1);
      uRPGTabs_Shop_ItemSet.extent = getWord(uRPGTabs_Shop_ItemSet.extent,0) SPC getWord(uRPGTabs_Shop_ItemSet.extent,1)+140;
   }

Add some echos to see where it goes wrong.

Code: [Select]
%object = new GuiSwatchCtrl("uRPGShopItem_" @ %strName)I'm pretty sure this doesn't work. Are there any console errors?

Code: [Select]
%object = new GuiSwatchCtrl("uRPGShopItem_" @ %strName)I'm pretty sure this doesn't work. Are there any console errors?
Not really.

Add some echos to see where it goes wrong.
Alright, I will see what I can do.

I also had to make dynamic names for GUIs at a point, I basically just set a variable equal to want I wanted the name to be
Code: [Select]
%name = "Derp" @ %i;then made the GUI using that variable
Code: [Select]
new GUISwatchCtrl(%name)

I also had to make dynamic names for GUIs at a point, I basically just set a variable equal to want I wanted the name to be
Code: [Select]
%name = "Derp" @ %i;then made the GUI using that variable
Code: [Select]
new GUISwatchCtrl(%name)

Exactly. The other option is to create them with a generic name and then rename them with ::setName.

Any of these weren't the issue. I figured it out.

It was the extent issue.

position = "188 171";
extent = "272" SPC getWord(uRPGTabs_Shop_ItemSet.extent,1);


When it was supposed to be:

position = "0" SPC getWord(uRPGTabs_Shop_ItemSet.extent,1);
extent = "272 140";






Works now :)
« Last Edit: November 17, 2013, 02:55:48 PM by Advanced Bot »

You should use custom profiles, because it doesn't look very appealing. Nice work though!