Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-26-2006, 11:07 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Math!

Hmm, what's wrong with these? Addition is the same way, and works fine, but none of these work x_X (the reason for the temp.display is to make the display flash, but still save the date for the block)
PHP Code:
function calc_subtract.onAction()
{
  
temp.display=calc_num.text;
  
calc_num.text="";
  
sleep .05;
  
calc_num.text=temp.display;
  
sleep .05;
  
calc_num.text="";
  
this.total-=temp.display;
    
this.calc_mode=2;
}
function 
calc_multiply.onAction()
{
  
temp.display=calc_num.text;
  
calc_num.text="";
  
sleep .05;
  
calc_num.text=temp.display;
  
sleep .05;
  
calc_num.text="";
  
this.total*=temp.display;
    
this.calc_mode=3;
}
function 
calc_divide.onAction()
{
  
temp.display=calc_num.text;
  
calc_num.text="";
  
sleep .05;
  
calc_num.text=temp.display;
  
sleep .05;
  
calc_num.text="";
  
this.total/=temp.display;
  
this.calc_mode=4;

Reply With Quote
  #2  
Old 05-26-2006, 11:48 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Why use sleep?
__________________
Skyld
Reply With Quote
  #3  
Old 05-27-2006, 12:07 AM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Quote:
Originally Posted by Skyld
Why use sleep?
It's to make the display 'blip' like a calculator does
Reply With Quote
  #4  
Old 05-27-2006, 01:10 PM
Tyrial Tyrial is offline
The Shiznic
Join Date: Dec 2001
Location: Sweden > Stockholm
Posts: 2,411
Tyrial is an unknown quantity at this point
Quote:
Originally Posted by excaliber7388
It's to make the display 'blip' like a calculator does
Use a timeout loop instead..

Edit:

If it's going to blip only a certain times, use a for loop.
Reply With Quote
  #5  
Old 05-27-2006, 03:29 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
I don't think the blip is contributing to the math errors. For example, 8-6 is not -14, however, that's what's showing up
Reply With Quote
  #6  
Old 05-27-2006, 05:53 PM
Shaun Shaun is offline
Registered User
Shaun's Avatar
Join Date: Jul 2003
Location: Canada
Posts: 1,070
Shaun is a jewel in the roughShaun is a jewel in the rough
It would be useful to see the rest of the algorithm in trying to come to a solution.

EDIT:

And those are GS1 sleeps, not GS2
Reply With Quote
  #7  
Old 05-27-2006, 06:33 PM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
Quote:
Originally Posted by Shaun
It would be useful to see the rest of the algorithm in trying to come to a solution.

EDIT:

And those are GS1 sleeps, not GS2
Good point XD
Since they're all the same (and none but addition work):
PHP Code:
  temp.display=calc_num.text;
  
calc_num.text="";
  
this.total-=temp.display;
    
this.calc_mode=2
as for the equals button:
PHP Code:
if(this.calc_mode==2)
  {
    
this.total-=calc_num.text;
  } 
Reply With Quote
  #8  
Old 05-27-2006, 07:57 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
The script looks ok, but the rest of the script which you have not shown might make problems, e.g. when calling setTimer(time) or setting timeout = time then 'sleeps' are stopped. You could eventually use scheduleevent(delay,action,params)
Reply With Quote
  #9  
Old 05-28-2006, 05:38 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
This may be a problem with what 'this.total' contains before/after you hit the subtraction sign.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #10  
Old 05-28-2006, 05:51 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by excaliber7388
PHP Code:
function calc_subtract.onAction()
{
  
// stuff
  
this.total-=temp.display;
  
// stuff
}
function 
calc_multiply.onAction()
{
  
// stuff
  
this.total*=temp.display;
  
// stuff
}
function 
calc_divide.onAction()
{
  
// stuff
  
this.total/=temp.display;
  
// stuff

I can't be sure, but it seems to me that the probem lies in these actions. I am supposing that these are to set the first number. In which case,
NPC Code:
this.total-=temp.display
this.total*=temp.display
this.total/=temp.display


should be
NPC Code:
this.total = temp.display



It seems to me what you are actually doing is
0 + 8 + 6 = 14 <- is correct
0 - 8 - 6 = -14
0 * 8 * 6 = 0
0 / 8 / 6 = 0

Last edited by Tolnaftate2004; 05-28-2006 at 06:02 PM..
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:50 PM.


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