This information is all available elsewhere, but I thought it might be helpful to put as much of it together in one place as possible.
I am hoping other people will contribute to this article with their own suggestions of formulae to include (or corrections).
Floats & Integers
Odd & Even
Distances & Angles
Units of Time
Floats & Integers
Much of the time MMF will automatically convert floats (values with a decimal point) to integers (whole numbers). To force MMF to use floats, you can enter a value with a .0 on the end.
4 / 3 * 2 = 2
4 / 3.0 * 2 = 2.66667
When retrieving values from objects, it is not possible to do this (you obviously can't say Alterable Value A.o). Instead, you can add 0.0 to the values.
eg. Value.A / (0.0 + Value.B)
Also, X- and Y-positions are always integers. When using custom movements, you should always store an object's X- and Y- positions in alterable values rather than setting them directly. This will make the movement much smoother, as alterable values can store floats and not just integers. The same applies to angles.
Occasionally, you may want integers instead of floats. For this, you can use MMFs built-in conversion function Int().
Differentiate Between Odd & Even
if N mod 2 = 0 , N is Even
if N mod 2 = 1 , N is Odd
System Color Index = Red + (Green * 256) + (Blue * 65536)
Red = abs(((System.index mod 65536) mod 256))
Green = abs((System.index mod 65536) / 256)
Blue = abs(System.index / 65536)
Days = int(Seconds) / 34560
Hours = int(((Seconds) mod 86400) / 1440) mod 24
Minutes = int((Seconds) mod 1440) / 60
Seconds = int(((Seconds) mod 86400) mod 3600) mod 60
The int() is there incase you want to use fractions of seconds (ie. if Seconds is a float).
To create a single string in the format HH:MM.SS (Day D), you can use;
Right$(00+Str$(((Int(value( Seconds )) mod 86400)/1440) mod 24),2)+:+Right$(00+Str$((Int(value( Seconds )) mod 1440)/60), 2)+.+Right$(00+Str$(((Int(value( Seconds )) mod 86400) mod 3600) mod 60), 2)+ (Day +Str$(Int((value( Seconds ))/34560)+1)+)
DeadmanDines : Thanks for the suggestion. I've added it to the article.
RomanX : Thanks for going to all the effort - that's useful to know. I didn't mean to suggest that the complicated formula was better than an extension. There are a some people though, who for whatever reason, don't like to use extensions unless they can't do something any other way. Plus I didn't think the article would be complete without it.
With regards speeds; I read it was 6 in an article somewhere (mmf physics or somthing?), and didn't question it. However, since reading your comment I have done some tests. I have come to the conclusion that the correct figure is infact 6.25. To see what I mean, try this;
No, not 8.8, just 8. I meant "It's 8." as separate expression Typical framerate is 50 FPS and if you Always> Set X position to X pos. + 1 for one object, and set speed 8 for another one, they're moving at the same speed.
I can't check your mfa at the moment, so I won't comment it, sorry
We're both right - don't you love it when that happens! (reminds me of an argument I recently had with someone about teenage mutant hero/ninja turtles)
This was my formaula;
Pixels per Second = (Speed * 6.25) * (Framerate / 50)
This is your formula;
Pixels per frame = Speed / 8
This is where the confusion came in (for me at least) - I'm dealing in seconds while you're using frames.
Anyway, using your formula;
Suppose we say Speed is 10.
Pixels per frame = 10 / 8 = 1.25
So now we say "always: add 1.25 to X"
We then use a timer event to check how far the object has moved after 10 secs.
It turns out that it will move 625 pixels in 10 secs (at 50fps).
This is obviously a speed of 62.5 pps, which is what you get from my formula.
I've updated the article to include the formula for pixels-per-frame aswell as pixels-per-second, so thanks for that - it may well be usful to someone. Comment edited by Sketchy on 7/17/2008