| 05-16-2007, 01:40 AM | #1 |
I need to find the distance between a unit and target of a spell, and set it to a variable. For some reason, I've been unable to find anything that can do that. How is this done? |
| 05-16-2007, 01:45 AM | #2 |
Trigger: Set REAL = (Distance between (Position of (Casting unit)) and (Position of (Target unit of ability being cast)))Edit: Or "target point of ability being cast". Your pick. |
| 05-16-2007, 01:55 AM | #3 |
Integer doesn't work? |
| 05-16-2007, 02:06 AM | #4 |
Yes, an integer does work, you just need to make a conversion. Trigger: Set Integer = (Integer((Distance between(Position of(triggering unit)) and (target point of ability being cast)))) |
| 05-16-2007, 02:07 AM | #5 |
Oh, so that's why I couldn't find it. What's the difference between an integer and a real? The fact that a real has to be a whole number? |
| 05-16-2007, 02:09 AM | #6 |
Isn't integer supposed to be a "whole" number? |
| 05-16-2007, 02:10 AM | #7 |
Integers = -1,0,1,2,3,4 Reals = 0, 0.1, 0.2, 0.342324 etc. |
| 05-16-2007, 02:14 AM | #8 |
Well, yes, an integer is a whole number and a real is a decimal, like Dil999 said, but in the WE, reals can do a few more things than be a decimal, like measure the distance between points or units, the angle between things, random angles, random numbers, life or mana properties of units, time of day etc. And integers have their own things that reals can't do as well, like measure the level of a unit, or the level of an ability for a unit, which is extremely helpful making trigger enhanced spells. Oh, and remember when you are using a real in a multiboard or something, like how many kills someone has got, it will say like 3.00 kills. It would be better using integers in things like that because they would just say 3 kills. |
| 05-16-2007, 08:19 AM | #9 |
real can do everything that integer can do. Its just about type casting them. But ofc integer take less memory which is a nice thing. And also its much easier to use integer. But in general real can represent integer, but integer cant represent real. . When you work with math in wc3, like distance, radius ect... always use real. Since integer isnt exact enough. If the distance is 0.3 integer will say its 0 |
| 05-16-2007, 10:02 AM | #10 | ||||
Quote:
Not really. Really, type casting is rarely the right way to go about it. If you need whole numbers, use integers. If you want fractions, use reals. Quote:
Integers and reals are both, like all variables, 4 bytes long. Quote:
Not really. Pretty much identicle except one will round down to an integer value. Quote:
Not really true. Reals will tend to be values like 3.0000005 for an integer of 3. Reals in WC3 are 4 byte floats (look it up on wikipedia if you don't know what that means). Integers are 4 byte signed integers. |
| 05-16-2007, 10:05 AM | #11 | |
Oh sorry, I thought there were a few things that Integers could do that Reals can't. But I was wrong :(. I know that reals are more accurate when dealing with angles, distance etc, but it really doesn't make much of a difference in most cases. Like if you wanted to find out the distance between the casting unit and the target point of ability being cast, it basically always doesn't matter if it gives you 500 distance, or 500.3. Lol cg, wanna use "Not really" any more times in a post? Quote:
Did you just make that up so you could just add another "Not Really"? Lol jk. Who really cares if you get a distance of 0.0000005 too much? |
| 05-16-2007, 10:28 AM | #12 | ||
Quote:
What happens if it is 0.0000005 on the other side? R2I(2.999999995) == 2. Normally it won't make any difference though. Quote:
All the natives for that are reals. Therefore, why use integers? Also, finding distances between stuff involves trig. Trig functions must be done in reals. It just wouldn't work with integers. |
| 05-16-2007, 11:27 AM | #13 |
Integers are mainly for simple things like player kills, scores, assists, array indexes. Reals are for geometry. Really, you can't have an array with something like "Unit[1.05]" or a distance of EXACTLY 500 units, the human brain simply cannot tell you to "Hey click here, this is exactly 500 units!" |
| 05-16-2007, 04:58 PM | #14 |
Reals are for anything where you need a non-integer value, integers are for everything else. Reals can 'represent' integers, but they lose the precision of integers as CG mentioned. |
