# Why doesn't this work? (Average script)

**URL:** https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732
**Category:** flash
**Created:** [August 29, 2003, 11:02pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732 "2003-08-29T23:02:05Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![babywax](https://avatars.discourse-cdn.com/v4/letter/b/7993a0/32.png) [@babywax](https://forum.kirupa.com/u/babywax)
#### Post date: [August 29, 2003, 11:02pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/1 "2003-08-29T23:02:05Z")

</div>

I can’t figure out why this won’t work…  
I’m trying to make a new Math function, called Math.halfway  
It adds two variables together and returns half of their value.  
The problem is, when I use it, on a value of 100 and 200, it comes up with 159.5? Why does it do this? Thank you for any help, the flash file is attached.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2003, 11:30pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/2 "2003-08-29T23:30:29Z")

</div>

Ok, I did a little testing with it and found out that the result is always 9.5 higher than it should be. This is easily patchable, but why does it not work in the first place?

[AS]  
Math.halfway = function (numOne, numTwo) {  
this.numOne = numOne;  
this.numTwo = numTwo;  
var num = this.numOne + this.numTwo;  
return num/2;  
delete this.numOne;  
delete this.numTwo;  
}  
[/AS]  
there’s the script.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 29, 2003, 11:32pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/3 "2003-08-29T23:32:21Z")

</div>

Sorry to spam, but I found out the symbol I was using was 9.5 off… I know, pretty stupid :sigh:

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 30, 2003, 3:23pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/4 "2003-08-30T15:23:25Z")

</div>

just wanted to offer you a little help with your function (cleaning it).

Also, adding two numbers and getting the halfway point between them is just the average of the two numbers, so try something like this.

[AS]Math.average = function (numOne, numTwo) {  
return (numOne+numTwo)/2;  
}[/AS]

Haven’t tested it, but that should return the same result. When you are passing variables to the function, just do it like this:

[AS]Math.average(this.numOne, this.numTwo)[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 30, 2003, 3:37pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/5 "2003-08-30T15:37:27Z")

</div>

Just in case you need the average of more than two numbers…  
[AS]Math.average = function() {  
var i, n;  
for (i=0; i\<arguments.length; i++) n += arguments\*;  
return n/arguments.length;  
};[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 30, 2003, 4:17pm UTC](https://forum.kirupa.com/t/why-doesnt-this-work-average-script/29732/6 "2003-08-30T16:17:44Z")

</div>

Hi babywax

Open the info panel (not property panel). There is an icon of 9 small boxes. Usually the left upper one is selected. You can change it to select the central one.

Then the \_x will be shown correctly in property panel.
