Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-07-2010, 07:06 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
Calculator script

I'm working on this calculator script, it's far from done, but i've already come across a problem.
this is my script.
PHP Code:
//#CLIENTSIDE
function onWeaponFired()
{
  new 
GuiWindowCtrl("Calculator")
  {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "165, 200";
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Calculator";
    
300;
    
200;
    
    new 
GuiTextEditCtrl("input")
    {
      
profile GuiBlueTextEditProfile;
      
5;
      
5;
      
width 155;
      
height 30;
      
text "";
    }
    new 
GuiButtonCtrl("Clear")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "Clear";
      
width 35;
      
5;
      
45;
    }
    new 
GuiButtonCtrl("plusmin")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+/-";
      
width 35;
      
45;
      
45;
    }
    new 
GuiButtonCtrl("divide")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "%";
      
width 35;
      
85;
      
45;
    }
    new 
GuiButtonCtrl("multiply")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "X";
      
width 35;
      
125;
      
45;
    }
        new 
GuiButtonCtrl("seven")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "7";
      
width 35;
      
5;
      
75;
    }
    new 
GuiButtonCtrl("eight")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "8";
      
width 35;
      
45;
      
75;
    }
    new 
GuiButtonCtrl("nine")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "9";
      
width 35;
      
85;
      
75;
    }
    new 
GuiButtonCtrl("subtract")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "-";
      
width 35;
      
125;
      
75;
    }
        new 
GuiButtonCtrl("four")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "4";
      
width 35;
      
5;
      
105;
    }
    new 
GuiButtonCtrl("five")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "5";
      
width 35;
      
45;
      
105;
    }
    new 
GuiButtonCtrl("six")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "6";
      
width 35;
      
85;
      
105;
    }
    new 
GuiButtonCtrl("add")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+";
      
width 35;
      
125;
      
105;
    }
        new 
GuiButtonCtrl("one")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "1";
      
width 35;
      
5;
      
135;
    }
    new 
GuiButtonCtrl("two")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "2";
      
width 35;
      
45;
      
135;
    }
    new 
GuiButtonCtrl("three")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "3";
      
width 35;
      
85;
      
135;
    }
    new 
GuiButtonCtrl("equals")
    {
      
profile GuiBlueButtonProfile;
      
height 55;
      
text "=";
      
width 35;
      
125;
      
135;
    }
    new 
GuiButtonCtrl("zero")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "0";
      
width 75;
      
5;
      
165;
    }
    new 
GuiButtonCtrl("dot")
    {
    
profile GuiBlueButtonProfile;
      
height 25;
      
text ",";
      
width 35;
      
85;
      
165;
    }
    
  }
}
function 
one.onAction()
{
  
input.text += 1;
}
function 
two.onAction()
{
  
input.text += 2;
}
function 
three.onAction()
{
  
input.text += 3;
}
function 
four.onAction()
{
  
input.text += 4;
}
function 
five.onAction()
{
  
input.text += 5;
}
function 
six.onAction()
{
  
input.text += 6;
}
function 
seven.onAction()
{
  
input.text += 7;
}
function 
eight.onAction()
{
  
input.text += 8;
}
function 
nine.onAction()
{
  
input.text += 9;

but the problem lies with these things
PHP Code:
function one.onAction()
{
  
input.text += 1;

instead of going 1, 11, 111 it goes, 1, 2, 3, so i need a way to add it as a string, and not as a number. Is there something like a str() function? so it will see it as a string?
__________________
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.
Reply With Quote
  #2  
Old 01-07-2010, 07:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Try

PHP Code:
function one.onAction() {
  
input.text @= 1;

Also, make sure to read this post.
__________________
Reply With Quote
  #3  
Old 01-07-2010, 07:49 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
I know you're not this far yet but I think Zero's or Pfa's eval() functions will help you out a treat when parsing the input.
Reply With Quote
  #4  
Old 01-07-2010, 07:49 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
i updated the script, it doesn't do anything with @= tho, no response in the texteditctrl.
also added the clear and "." button.
PHP Code:
//#CLIENTSIDE
function onWeaponFired()
{
  new 
GuiWindowCtrl("Calculator_window")
  {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "165, 200";
    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Calculator";
    
300;
    
200;
    
    new 
GuiTextEditCtrl("Calculator_input")
    {
      
profile GuiBlueTextEditProfile;
      
5;
      
5;
      
width 155;
      
height 30;
      
text="0";
    }
    new 
GuiButtonCtrl("Calculator_clear")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "Clear";
      
width 35;
      
5;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_plusmin")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+/-";
      
width 35;
      
45;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_divide")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "%";
      
width 35;
      
85;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_multiply")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "X";
      
width 35;
      
125;
      
45;
    }
        new 
GuiButtonCtrl("Calculator_seven")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "7";
      
width 35;
      
5;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_eight")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "8";
      
width 35;
      
45;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_nine")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "9";
      
width 35;
      
85;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_subtract")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "-";
      
width 35;
      
125;
      
75;
    }
        new 
GuiButtonCtrl("Calculator_four")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "4";
      
width 35;
      
5;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_five")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "5";
      
width 35;
      
45;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_six")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "6";
      
width 35;
      
85;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_add")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+";
      
width 35;
      
125;
      
105;
    }
        new 
GuiButtonCtrl("Calculator_one")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "1";
      
width 35;
      
5;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_two")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "2";
      
width 35;
      
45;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_three")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "3";
      
width 35;
      
85;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_equals")
    {
      
profile GuiBlueButtonProfile;
      
height 55;
      
text "=";
      
width 35;
      
125;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_zero")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "0";
      
width 75;
      
5;
      
165;
    }
    new 
GuiButtonCtrl("Calculator_dot")
    {
    
profile GuiBlueButtonProfile;
      
height 25;
      
text ",";
      
width 35;
      
85;
      
165;
    }
    
  }
}
function 
Calculator_one.onAction()
{
  if(
input.text 0)
  {
    
input.text 1;
  }
  else
  {
    
input.text @= 1;
  }
}
function 
Calculator_two.onAction()
{
  if(
input.text 0)
  {
    
input.text 2;
  }
  else
  {
    
input.text @= 2;
  }
}
function 
Calculator_three.onAction()
{
  if(
input.text 0)
  {
    
input.text 3;
  }
  else
  {
    
input.text @= 3;
  }
}
function 
Calculator_four.onAction()
{
  if(
input.text 0)
  {
    
input.text 4;
  }
  else
  {
    
input.text @= 4;
  }
}
function 
Calculator_five.onAction()
{
  if(
input.text 0)
  {
    
input.text 5;
  }
  else
  {
    
input.text @= 5;
  }
}
function 
Calculator_six.onAction()
{
  if(
input.text 0)
  {
    
input.text 6;
  }
  else
  {
    
input.text @= 6;
  }
}
function 
Calculator_seven.onAction()
{
  if(
input.text 0)
  {
    
input.text 7;
  }
  else
  {
    
input.text @= 7;
  }
}
function 
Calculator_eight.onAction()
{
  if(
input.text 0)
  {
    
input.text 8;
  }
  else
  {
    
input.text @= 8;
  }
}
function 
Calculator_nine.onAction()
{
  if(
input.text 0)
  {
    
input.text 9;
  }
  else
  {
    
input.text @= 9;
  }
}
function 
Calculator_clear.onAction()
{
  
input.text 0;
}
function 
Calculator_dot.onAction()
{
  
input.text @= ".";

__________________
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.
Reply With Quote
  #5  
Old 01-07-2010, 07:51 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
You have to change input.text into Calculator_input.text

You should also look into catchevent(), so you have one event to handle all the button clicking
__________________
Reply With Quote
  #6  
Old 01-07-2010, 07:52 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
You renamed "input" to "Calculator_input", but forgot to rename it in the functions

PHP Code:
function Calculator_one.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 1;
  }
  else
  {
    
Calculator_input.text @= 1;
  }

Also, make sure you use "==" when comparing variables instead of "="; a single equality sign is used for assigning values to variables, and two signs are used for comparisons.

edit: damn you Chompy
__________________
Reply With Quote
  #7  
Old 01-07-2010, 07:57 PM
Liberated Liberated is offline
not doing alot
Liberated's Avatar
Join Date: Feb 2008
Posts: 1,366
Liberated has a spectacular aura about
Quote:
Originally Posted by cbk1994 View Post
You renamed "input" to "Calculator_input", but forgot to rename it in the functions

PHP Code:
function Calculator_one.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 1;
  }
  else
  {
    
Calculator_input.text @= 1;
  }

Also, make sure you use "==" when comparing variables instead of "="; a single equality sign is used for assigning values to variables, and two signs are used for comparisons.

edit: damn you Chompy
ah silly me, completely forgot about that,
and yeah, i know about the == for comparing and = for assigning, i somehow randomly keep forgetting to add the == for comparing.

edit:
awesome, now it's working as planned for this far.

editedit:
i finished it!
PHP Code:
//#CLIENTSIDE
function onWeaponFired()

  
this.number1 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";
    
300;
    
200;
    
    new 
GuiTextEditCtrl("Calculator_input")
    {
      
profile GuiBlueTextEditProfile;
      
5;
      
5;
      
width 155;
      
height 30;
      
text="0";
    }
    new 
GuiButtonCtrl("Calculator_clear")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "Clear";
      
width 35;
      
5;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_plusmin")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+/-";
      
width 35;
      
45;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_divide")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "%";
      
width 35;
      
85;
      
45;
    }
    new 
GuiButtonCtrl("Calculator_multiply")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "X";
      
width 35;
      
125;
      
45;
    }
        new 
GuiButtonCtrl("Calculator_seven")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "7";
      
width 35;
      
5;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_eight")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "8";
      
width 35;
      
45;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_nine")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "9";
      
width 35;
      
85;
      
75;
    }
    new 
GuiButtonCtrl("Calculator_subtract")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "-";
      
width 35;
      
125;
      
75;
    }
        new 
GuiButtonCtrl("Calculator_four")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "4";
      
width 35;
      
5;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_five")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "5";
      
width 35;
      
45;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_six")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "6";
      
width 35;
      
85;
      
105;
    }
    new 
GuiButtonCtrl("Calculator_add")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "+";
      
width 35;
      
125;
      
105;
    }
        new 
GuiButtonCtrl("Calculator_one")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "1";
      
width 35;
      
5;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_two")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "2";
      
width 35;
      
45;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_three")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "3";
      
width 35;
      
85;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_equals")
    {
      
profile GuiBlueButtonProfile;
      
height 55;
      
text "=";
      
width 35;
      
125;
      
135;
    }
    new 
GuiButtonCtrl("Calculator_zero")
    {
      
profile GuiBlueButtonProfile;
      
height 25;
      
text "0";
      
width 75;
      
5;
      
165;
    }
    new 
GuiButtonCtrl("Calculator_dot")
    {
    
profile GuiBlueButtonProfile;
      
height 25;
      
text ",";
      
width 35;
      
85;
      
165;
    }
    
  }
}
function 
Calculator_one.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 1;
  }
  else
  {
    
Calculator_input.text @= 1;
  }
}
function 
Calculator_two.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 2;
  }
  else
  {
    
Calculator_input.text @= 2;
  }
}
function 
Calculator_three.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 3;
  }
  else
  {
    
Calculator_input.text @= 3;
  }
}
function 
Calculator_four.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 4;
  }
  else
  {
    
Calculator_input.text @= 4;
  }
}
function 
Calculator_five.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 5;
  }
  else
  {
    
Calculator_input.text @= 5;
  }
}
function 
Calculator_six.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 6;
  }
  else
  {
    
Calculator_input.text @= 6;
  }
}
function 
Calculator_seven.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 7;
  }
  else
  {
    
Calculator_input.text @= 7;
  }
}
function 
Calculator_eight.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 8;
  }
  else
  {
    
Calculator_input.text @= 8;
  }
}
function 
Calculator_nine.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 9;
  }
  else
  {
    
Calculator_input.text @= 9;
  }
}
function 
Calculator_zero.onAction()
{
  if(
Calculator_input.text == 0)
  {
    
Calculator_input.text 0;
  }
  else
  {
    
Calculator_input.text @= 0;
  }
}
function 
Calculator_clear.onAction()
{
  
Calculator_input.text 0;
}
function 
Calculator_dot.onAction()
{
  
Calculator_input.text @= ".";
}
function 
Calculator_plusmin.onAction()
{
  
Calculator_input.text -= Calculator_input.text;
}
function 
Calculator_divide.onAction()
{
  
this.number1 Calculator_input.text;
  
this.divide 1;
  
Calculator_input.text "0";
}
function 
Calculator_add.onAction()
{
  
this.number1 Calculator_input.text;
  
this.add 1;
  
Calculator_input.text "0";
}
function 
Calculator_subtract.onAction()
{
  
this.number1 Calculator_input.text;
  
this.subtract 1;
  
Calculator_input.text "0";
}
function 
Calculator_multiply.onAction()

  
this.number1 Calculator_input.text;
  
this.multiply 1;
  
Calculator_input.text "0";
}
function 
Calculator_equals.onAction()
{
  if(
this.divide == 1)
  {
    
this.divide 0;
    
Calculator_input.text = (this.number1 Calculator_input.text);
    
this.number1 0;
  }
  else if(
this.add == 1)
  {
    
this.add 0;
    
Calculator_input.text += this.number1;
  }
  else if(
this.subtract == 1)
  {
    
Calculator_input.text this.number1 Calculator_input.text;
    
this.subtract 0;
    
this.number1 0;
  }
  else if(
this.multiply == 1)
  {
    
Calculator_input.text this.number1 Calculator_input.text;
    
this.number1 0;
    
this.multiply 0;
  }

1 thing i plan on fixing in the future,
right now you cannot do for example: 8*8*8*8=
but you have to do 8*8=64*8=somehugenumber
so you have to press the = after each equation, im still quite happy with it,
__________________
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-07-2010 at 08:35 PM..
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:40 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.