zerodowned

Moderator
In my script Spellbar, each spell selected sends a button to a new gump that acts like a hotbar. The position of each button added to the hotbar is based on a calculation. I have tried to call a Method with the calculation in it, instead of placing the Calculation in each button in order to greatly reduce the size of the script and provide one central area of the script to modify the calculation instead of having to change the calculation in ~140 different places.

Here's the part of the script I'm refering to, down to the first button:
C#:
/////////////////////////////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
////******** spellbar_bargump  ************////
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

////////////////////////////

  public class SpellBar_BarGump : Gump
  {
   
     
     
  public static bool HasSpell( Mobile from, int spellID )
  {
  Spellbook book = Spellbook.Find( from, spellID );
  return ( book != null && book.HasSpell( spellID ) );
  }

  private SpellBarScroll m_Scroll;
     private int m_Dbx;
     private int m_Dbxa;
     private int m_Dby;
     private int m_Dbya;
     public int mXselect_var;
     public int mYselect_var;
   
/*
     public void CalcPos ( )
     {
       int dbx = 0; //dbx = 50;
           int dbxa = 0; //dbxa = 45;
           int dby = 0; //dby = 5;
           int dbya = 0; //dbya = 0;
           int xselect_var = 0; //xselect_var = 0;
     
         if ( m_Scroll.mXselect_10 == 1) { xselect_var = 562; }
         if ( m_Scroll.mXselect_15 == 1) { xselect_var = 787; }
         if ( m_Scroll.mXselect_20 == 1) { xselect_var = 1012;  }
         if ( m_Scroll.mXselect_30 == 1) { xselect_var = 1462;  }
         
         if ( dbx + dbxa >= xselect_var & dby + dbya == 5 ) { dbx = 67; dbxa = 45; dby = 50; dbya = 0; }  
         if ( dbx + dbxa >= xselect_var & dby + dbya == 50 ) { dbx = 67; dbxa = 45; dby = 95; dbya = 0; }
         if ( dbx + dbxa >= xselect_var & dby + dbya == 95 ) { dbx = 67; dbxa = 45; dby = 140; dbya = 0; }  
         
         if ( m_Scroll.mSwitch == 1 )
         {  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 0 ) { dbx = 45; dbxa = 0; dby = 54; dbya = 45; }  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 45 ) { dbx = 90; dbxa = 0; dby = 54; dbya = 45; }  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 90 ) { dbx = 135; dbxa = 0; dby = 54; dbya = 45; }
         }
         
         
     }
   */
     
     

  public SpellBar_BarGump( Mobile from, int dbx, int dbxa, int dby, int dbya, int xselect_var, SpellBarScroll scroll ) : base( 0, 0 )
  {
  m_Scroll = scroll;
       m_Dbx = dbx;
       m_Dbxa = dbxa;
       m_Dby = dby;
       m_Dbya = dbya;
       mXselect_var = xselect_var;
       
       
       if ( m_Scroll.mLock == 0 )
       {
         this.Closable=true;
         this.Disposable=true;
         this.Dragable=true;
         this.Resizable=false;
       }
       else
       {
         this.Closable=false;
         this.Disposable=true;
         this.Dragable=false;
         this.Resizable=false;
       }
       
       
       
       this.AddPage(1);
         
         
       if ( m_Scroll.mSwitch == 0 )
       {
         
         
         AddImage( 24, 0, 2234, 0);
         AddImageTiled( 0,0, 25,80, 2624 ); //options background
         AddAlphaRegion(0, 0, 25, 80);
         
           if ( m_Scroll.mLock == 0 )
           {
             dbx = 67; dbxa = 45; dby = 5; dbya = 0;

             this.AddButton( 2, 28,  22404, 22404, 138, GumpButtonType.Reply, 1); // flip button
             this.AddButton( 2, 5,  5603, 5603, 0, GumpButtonType.Page, 2); // minimize
             this.AddButton( 5, 54,  2510, 2510, 139, GumpButtonType.Reply, 1); // unlocked
           }
           else
           {
             this.AddButton( 5, 54,  2092, 2092, 139, GumpButtonType.Reply, 1); // locked
           }
       }
       else
       {
           dbx = 0; dbxa = 0; dby = 54; dbya = 45;
           
           AddImage( 0, 0, 2234, 0);
           AddImageTiled( 42,0, 47,51, 2624 ); //options background
           AddAlphaRegion(42, 0, 47, 51);
           
           if ( m_Scroll.mLock == 0 )
           {
             this.AddButton( 48, 28,  22404, 22404, 138, GumpButtonType.Reply, 1); // flip button
             this.AddButton( 48, 7,  5600, 5600, 0, GumpButtonType.Page, 3); // minimize
             this.AddButton( 70, 16,  2510, 2510, 139, GumpButtonType.Reply, 1); // unlocked
           }
           else
           {
             this.AddButton( 70, 16,  2092, 2092, 139, GumpButtonType.Reply, 1); // locked
           }
           
           
       }
       
   // magery 1015164 - 1015227, except for Circle # clilocs: 1015171 , 1015177 , 1015185 ,
   
   //1015193 , 1015202 ,

   //1015210 , 1015219
   // necro 1060509 - 1060525
   // chiv 1060493 - 1060502
   // bush 1060595 - 1060600
   // nin 1060610 - 1060617
   // sw 1031601 - 1031616
   // myst 1031678 - 1031693
  if ( HasSpell( from, 0 ) && m_Scroll.mW00_ClumsySpell == 1)
       {
         this.AddButton(dbx, dby, 2240, 2240, 1, GumpButtonType.Reply, 1);
       
         dbx = dbx + dbxa; dby = dby + dbya;
         
         if ( m_Scroll.mXselect_10 == 1) { xselect_var = 562; }
         if ( m_Scroll.mXselect_15 == 1) { xselect_var = 787; }
         if ( m_Scroll.mXselect_20 == 1) { xselect_var = 1012;  }
         if ( m_Scroll.mXselect_30 == 1) { xselect_var = 1462;  }
         
         if ( dbx + dbxa >= xselect_var & dby + dbya == 5 ) { dbx = 67; dbxa = 45; dby = 50; dbya = 0; }  
         if ( dbx + dbxa >= xselect_var & dby + dbya == 50 ) { dbx = 67; dbxa = 45; dby = 95; dbya = 0; }
         if ( dbx + dbxa >= xselect_var & dby + dbya == 95 ) { dbx = 67; dbxa = 45; dby = 140; dbya = 0; }  
         
         if ( m_Scroll.mSwitch == 1 )
         {  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 0 ) { dbx = 45; dbxa = 0; dby = 54; dbya = 45; }  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 45 ) { dbx = 90; dbxa = 0; dby = 54; dbya = 45; }  
           if ( dby + dbya >= xselect_var - 13 & dbx + dbxa == 90 ) { dbx = 135; dbxa = 0; dby = 54; dbya = 45; }
         }
         
         //CalcPos();
         AddTooltip( 1015164 );
       }

Trying to use the Method to place the button has resulted in nothing happening.
I have a few guesses what the problem is, but I'm still learning and stumped after trying multiple options.

Thanks for any help.
 
Try making it static. The constructor takes place at the creation of the object at which point methods are generated for each object, making it static will essentially define it before the creation of the object and might allow you to access it before the construction of the object which is what you need to happen. If not you could make a static class containing the method outside the gump.

++ And this is because only one instance of the static method exists for all objects of type.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back