I'm trying to use the
distance(atom/M,atom/N)
return sqrt((N.x-M.x)**2 + (N.y-M.y)**2)
proc from AbyssDragons BasicMath library. How would I return the distance into one variable
I made this:
var/distance = 0
distance(distance)
obviously it isnt working, I didn't think it would..
How would I do that? Thank you for your time!
ID:176165
![]() Feb 11 2003, 2:49 pm
|
|
Well, i did this
var/dist = distance(mob/M,mob/N) i dont know if that's what you mean. But i'm getting an error that N is an undenified Variable |
SSChicken wrote:
Well, i did this No no.. You must provide two things.. mob/verb/Get_Distance(mob/M in world, atom/A in world) ~>Volte |
Well, I'm making a proc, that uses that. It check the distance between the user and the other mob(either monster or player) then according to that it send out that many beams. Basicly all I need to know is how to get the distance number to a single variable and I'm good. The code before didn't help me.
((Sorry for so many posts)) |
It does return a single value.
<code>var/dist=distance(blah,whatever)</code> That is one variable. Duh. |
SSChicken wrote:
I'm trying to use the Ouch! I hope he rewrites that sometime. The ** operator is hideous. A better distance formula would be like this: proc/distance(atom/M,atom/N) How would I return the distance into one variable I have no idea what you mean by "return the distance into one variable". If you mean how to get the result from the proc, you do it just like with any other proc:
var/dist = distance(M,N)
Lummox JR |
Lummox JR wrote: for that I get an error: Procs.dm:538:error:M:undefined var Procs.dm:538:error:N:undefined var now what is wrong? |
You get those errors for the exact reason it says - M and N aren't defined! =P
Don't use M and N in there; use whatever vars hold the atoms you want to find the distance between. So for example, if you want to find the distance between <code>src</code> and <code>A</code> (assuming you've declared A to be a var, and set it to the correct atom), call <code>distance(src,A)</code> |
Crispy wrote:
You get those errors for the exact reason it says - M and N aren't defined! =P Since SSChicken didn't specify which things he wanted to take the distance of, I just used the same vars that are used in the proc itself. Of course this shouldn't really have been a problem for anyone who was paying enough attention. The problem seems to be that SSChicken is copying code wholesale and plugging it in without taking a second look at how it's supposed to fit. It should have been easy to see when I said the call would be like distance(M,N) to know that, if M and N aren't defined in the calling proc, obviously I must have meant that M would be one thing and N would be another. Furthermore, I had reason to assume the call would be distance(M,N), because his mistaken call was N.distance(M). Those were the vars he apparently had chosen to use, but it now looks like he just pulled them out of the distance() proc itself without realizing they didn't belong in the calling proc. Lummox JR |
A better distance formula would be like this: proc/distance(atom/M,atom/N) What makes x * x any better than x**2 in the code? It's the sa... ...Oh. The ** operator must run an internal for loop, now that I think about it. ...Well, looks like I'm going to have some converting to do. =P |
...Oh. The ** operator must run an internal for loop, now that I think about it. Since you can also have non integer powers I don't think a loop is used unless it's for a special case. |
Spuzzum wrote:
What makes x * x any better than x**2 in the code? It's the sa... It may run a for() loop internally, which would still be an improvement over what I suspect it does. In C's math library, pow(a,b) is defined simply as exp(ln(a)*b). You can imagine some of the problems that causes, particularly with negative values of a and integer b's. (Just to think--with complex numbers there's no problem at all.) I think it's likely that ** internally only uses pow(), and doesn't resort to a for() loop. That'd still be worse than precalculating the vars and multiplying. Lummox JR |
From how that proc is made I would think you'd have to do this;
var/dist = distance(Mob, Atom)
~>Volte