Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Math! (https://forums.graalonline.com/forums/showthread.php?t=66257)

excaliber7388 05-26-2006 11:07 PM

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;



Skyld 05-26-2006 11:48 PM

Why use sleep? :confused:

excaliber7388 05-27-2006 12:07 AM

Quote:

Originally Posted by Skyld
Why use sleep? :confused:

It's to make the display 'blip' like a calculator does :D

Tyrial 05-27-2006 01:10 PM

Quote:

Originally Posted by excaliber7388
It's to make the display 'blip' like a calculator does :D

Use a timeout loop instead..

Edit:

If it's going to blip only a certain times, use a for loop.

excaliber7388 05-27-2006 03:29 PM

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

Shaun 05-27-2006 05:53 PM

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

excaliber7388 05-27-2006 06:33 PM

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;
  } 


Admins 05-27-2006 07:57 PM

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)

ApothiX 05-28-2006 05:38 AM

This may be a problem with what 'this.total' contains before/after you hit the subtraction sign.

Tolnaftate2004 05-28-2006 05:51 PM

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


All times are GMT +2. The time now is 02:41 PM.

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