View Single Post
  #8  
Old 01-08-2010, 06:55 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
V2.0 is done!
PHP Code:
//#CLIENTSIDE
function onWeaponFired()
{
  
this.number1 = 1;
  
this.number2 = 0;
  
this.divide = 0;
  
this.add = 0;
  
this.subtract = 0;
  
this.multiply = 0;
  new 
GuiWindowCtrl("Calculator_window")
  {
    
profile = GuiBlueWindowProfile;
    
clientrelative = true;
    
clientextent = "165, 200";
    
canmove = true;
    
canresize = false;
    
closequery = false;
    
destroyonhide = true;
    
text = "Calculator";
    
x = 300;
    
y = 200;
    
    new 
GuiTextEditCtrl("Calculator_input")
    {
      
profile = GuiBlueTextEditProfile;
      
useownprofile = true;
      
profile.align = "right"; 
      
x = 5;
      
y = 5;
      
width = 155;
      
height = 30;
      
text="0";
    }
    new 
GuiButtonCtrl("Calculator_clear")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "Clear";
      
width = 35;
      
x = 5;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_plusmin")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "+/-";
      
width = 35;
      
x = 45;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_divide")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "/";
      
width = 35;
      
x = 85;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_multiply")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "X";
      
width = 35;
      
x = 125;
      
y = 45;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_seven")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "7";
      
width = 35;
      
x = 5;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_eight")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "8";
      
width = 35;
      
x = 45;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_nine")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "9";
      
width = 35;
      
x = 85;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_subtract")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "-";
      
width = 35;
      
x = 125;
      
y = 75;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_four")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "4";
      
width = 35;
      
x = 5;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_five")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "5";
      
width = 35;
      
x = 45;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_six")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "6";
      
width = 35;
      
x = 85;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_add")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "+";
      
width = 35;
      
x = 125;
      
y = 105;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
        new 
GuiButtonCtrl("Calculator_one")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "1";
      
width = 35;
      
x = 5;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_two")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "2";
      
width = 35;
      
x = 45;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_three")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "3";
      
width = 35;
      
x = 85;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_equals")
    {
      
profile = GuiBlueButtonProfile;
      
height = 55;
      
text = "=";
      
width = 35;
      
x = 125;
      
y = 135;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_zero")
    {
      
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = "0";
      
width = 75;
      
x = 5;
      
y = 165;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }
    new 
GuiButtonCtrl("Calculator_dot")
    {
    
profile = GuiBlueButtonProfile;
      
height = 25;
      
text = ".";
      
width = 35;
      
x = 85;
      
y = 165;
      
thiso.catchEvent(this, "onAction", "buttonPressed");
    }   
  }
}
function 
ButtonPressed(obj)
{
  if(
obj.text in |0, 9|)
  {
    if(
Calculator_input.text == "0")
    {
      
Calculator_input.text = obj.text;
    }
    else
    {
      
Calculator_input.text @= obj.text;
    }
  }
  else if(
obj.text == ".")
  {
    
    
Calculator_input.text @= obj.text;
  }
  else if(
obj.text == "+/-")
  {
    
Calculator_input.text -= 2 * Calculator_input.text;
  }
  else if(
obj.text == "X")
  { 
    if(
this.divide == 1)
    {
      
this.divide = 0;
      
Calculator_input.text = (this.number1 / Calculator_input.text);
    }
    else if(
this.add == 1)
    {
      
this.add = 0;
      
Calculator_input.text += this.number2;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text = this.number2 - Calculator_input.text;
      
this.subtract = 0;
    }
    
this.divide = 0;
    
this.add = 0;
    
this.subtract = 0;
    
this.multiply = 1;
    
this.number1 *= Calculator_input.text;
    
Calculator_input.text = "0";
  }
  else if(
obj.text == "/")
  {
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 = 1;
    }
    else if(
this.add == 1)
    {
      
this.add = 0;
      
Calculator_input.text += this.number2;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text = this.number2 - Calculator_input.text;
      
this.subtract = 0;
    }
    
this.multiply = 0;
    
this.add = 0;
    
this.subtract = 0;
    
this.divide = 1;
    
this.number1 = Calculator_input.text / this.number1;
    
Calculator_input.text = "0";
  }
  else if(
obj.text == "+")
  { 
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 = 1;
    }
    else if(
this.divide == 1)
    {
      
this.divide = 0;
      
Calculator_input.text = (this.number1 / Calculator_input.text);
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text = this.number2 - Calculator_input.text;
      
this.subtract = 0;
    }
    
this.multiply = 0;
    
this.divide = 0;
    
this.subtract = 0;
    
this.add = 1;
    
this.number2 += Calculator_input.text;
    
Calculator_input.text = "0";
  }
  else if(
obj.text == "-")
  { 
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.multiply = 0;
    }
    else if(
this.divide == 1)
    {
      
this.divide = 0;
      
Calculator_input.text = (this.number1 / Calculator_input.text);
    }
    else if(
this.add == 1)
    {
      
this.add = 0;
      
Calculator_input.text += this.number2;
    }
    
this.subtract = 1;
    
this.number2 = Calculator_input.text - this.number2;
    
Calculator_input.text = "0";
  }
  else if(
obj.text == "=")
  {
    if(
this.multiply == 1)
    {
      
Calculator_input.text *= this.number1;
      
this.number1 = 1;
      
this.multiply = 0;
      
this.number2 = 0;
    }
    else if(
this.divide == 1)
    {
      
this.divide = 0;
      
Calculator_input.text = (this.number1 / Calculator_input.text);
      
this.number1 = 1;
      
this.number2 = 0;
    }
    else if(
this.add == 1)
    {
      
this.add = 0;
      
Calculator_input.text += this.number2;
      
this.number2 = 0;
      
this.number1 = 1;
    }
    else if(
this.subtract == 1)
    {
      
Calculator_input.text = this.number2 - Calculator_input.text;
      
this.subtract = 0;
      
this.number1 = 1;  
      
this.number2 = 0;
    }
  }
  else if(
obj.text == "Clear")
  {
    
Calculator_input.text = 0;
    
this.number1 = 1;  
    
this.number2 = 0;   
  } 
} 
it looks exactly the same but it's 2 times as good!
I used the catchEvent() thing, and now you don't have to do8*8=64 * 8= etc.
now you can just do 8*8*8=, or even 8*8+3/2
however, to make this possible, quite alot more code was used, and despite catchEvent(), it now has exactly as much lines as it used to have
it doesn't use bodmas tho. and it just does the calculations in the sequence you put it in.
right align also works now.
@fowlplay4,
i haven't been able to align it to the right. any tips? fixed, thanks
__________________
Quote:
Originally Posted by Tigairius View Post
I promise when I get rich I'll send you an iPhone. I'll send everyone an iPhone.

Last edited by Liberated; 01-08-2010 at 07:07 PM..
Reply With Quote