To be clear the reason my syntax looks a little different from the trigger editor (or I use the wrong word) is because I'm typing from memory and not because I'm opening the trigger editor and copying some other function you don't see. There are discrepancies when I don't remember the correct wording (or forget that flying height change requires a rate argument).
Yes.
Yes.
Do not use the field reader native for this, that's not what I wrote and it probably either doesn't work or doesn't update. There is an actual function that returns a real called "Unit - Flying Height (Current)" that you can find in the trigger editor. It returns a real value because heights are real values... not integers. You will not find it when looking at other things that return integers because it isn't an integer.
Since you used the wrong function, that probably reads 0 from that field so Height_Max (btw you spelled this one wrong and named your variable Heigh_Max) Height_Delta, and CH_Set_Height will all also be 0.
Do not use the field native to try to set fly height, there's an actual function for setting fly height you should be using. That function expects a 'rate of change' argument, and you can just put 0 there to make it instantaneous.
You should be able to look at what value the variable is being set to and determine the type of variable from context alone.
Height_Max reads the unit's flying height which is a real so it must also be a real.
CH_ConfChainHeight, the value
Min is assigned to, is also a real so
Min must be a real. (Another way: if
Max is a real, why wouldn't
Min also be a real?)
Height_Delta is just a proportional part of the difference between
Max and
Min, so it must also be a real. Again, the flying height we want things to have is a real value (not an integer) so the variable that holds the final computed
CH_Set_Height is also still a real.
I guess you became confused when you saw
CH_Loop[3] being used in the Set Height computation because I didn't type
Real(CH_Loop[3]). You really should not be confused by that; integers and reals are often used in many computations together so you will need to be familiar with 'converting' between them. The vast majority of the time you will
always want to work with real numbers, because operations with integers truncate and never round:
- 5.0/4.0 = 1.25
- 5/4 = 1 in integer-land because it truncated
- 99/100 = 0 in integer-land
- 5.0/4 = 1.25 even though the 4 was an integer; since it was directly involved in a computation with a non-integer variable, the result is a real'
- 3.5 \* (7/10) = 0.0 again (but a real this time not an integer). Because the 7/10 is an integer operation it will reduce to 0 first and then multiply the 3.5 to give a total of 0.0
I hate writing
Real() in a bunch of places just because GUI is so on-rails it won't let you substitute an integer for a real even though it would work just fine in JASS and Lua directly.