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

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.

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.

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

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]

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]

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.