Since it is getting an increasingly difficult issue for me to face, I figure I would ask it here.
Trigger variables only contain integers right (whole numbers) now. But I want to add more advanced math functions like "divide", "sin", "cos", "sqrt", "random" and stuff. The problem with adding these is that it would require handling both integer and float numbers in triggers. And the biggest problem with using floats for triggers is that they aren't perfectly commutative (0.2 + 0.1 - 0.1 = 0.20000000000000004), so it's possible that people would blame the game for a code not working because it relies on adding numbers together perfectly. Note that a branch if equal would
not work on "if 0.20000000000000004 == 0.2".
So I was thinking of doing something a little more interesting and adding a couple of instructions that work like an FPU. This means that I would leave integer operations as they are, and those always expect the input to be integer, if they aren't they would be type cast to an integer (rounded down). And then I would have a set of floating point operations which type cast any integers to floats if they are used as inputs.
This would leave the following triggers instructions:
Integer Operations:- Set (rounds down if you used a float)
- Add (should the numbers round down before or after the add is applied? ".6 + 1.6 = 2.2 -> 2" or "0.6 + 1.6 = 0 + 1 -> 1"?)
- Subtract
- Multiply
- Divide (returns a whole number rounded down)
- Mod (returns the remainder of a divide)
- Random (sets a random whole number between a and b)
Floating Point Operations:- Set
- Add
- Subtract
- Multiply
- Divide
- Power
- Sqrt
- Log
- Sin
- Cos
- Mod
- Random (sets a random number between 0 and 1)
Then in addition, since you can use functions like Sin and Cos I would add math constants for PI, and E.
All of this could make a couple of complex trigger functions to be simplified a lot. And there are other pretty cool uses for it. Like if you were allowed to input numbers into the "Move Item" instruction, you could set the x or y position to follow a sine wave.
I also like the idea of adding OOP styled accessors for an item's variables because it would be useful to read an X or Y of something and store it to a variable. Like so: "Add: myItem.x = myItem.x + 1". So you could bypass the need for the Move Item instruction. You would even be able to do that locally if you are writing a trigger for
myItem: "Add: x = x + 1". But that means I have to reserve simple variable names like "x", "y", and even "rotation". Is everyone okay with that?