actualy i was just an idiot and though that if i write % mark it would (just as using your calculator) divide. forgoten this obvious fact that 10% are in fact 0.10, and to get 10% of something i need it be multiply by 0.10.
Don't be too harsh to yourself. It's just learning by doing, we all come to such points from time to time
* off-topic *
And here a description of the modulo operation:
The percentage sign, when used outside of a string, is an operator, just like +, -, *, /, etc. And it does divide, but a modulo division, aka 'mod', giving the integer remainder of the division:
13 % 5 = 3
-> can also be expressed by: 13 - floor(13 / 5) * 5
-> you can also do ((13 / 5) - floor(13 / 5)) * 5
-> it is just returning the decimal places of the division multiplied by the denominator
Modulo is often used in programming to get a repeating list of ordered numbers.
For example, the timer returns the milliseconds passed since start of the application. You want a sprite to constantly fade in and out repeatedly and every fade should last 1 second. But the sprite's opacity is expressed by a value ranging from 0 to 100. So what we need is converting the timer value in a way that we get a value repeatedly growing and shrinking between 0 and 100.
13 / 5 = 2.6; 0.6 * 5 = 3
The first issue is solved by floor-dividing timer by 10.
The second issue is solved with two other tricks. First, we set the denominator to 201. This way the values returned will range from 0 to 200. Second, we make use of 'abs', which returns the absolute value of a number regardless of its sign (-4 and 4 both have the absolute value 4)
The final expression now is: opacity = abs(100 - floor(Timer / 10) % 201)
The returned values will be [100, 99, 98, ..., 2, 1, 0, 1, 2, ..., 98, 99, 100, 99, 98, ...] and every range 0-100 or 100-0 will last 1 second
- There are 1000 milliseconds in one second, but we need one second to be 100.
- If doing 'timer % 100', the results returned will raise from 0 to 99, then immediatly fall back to 0 and raise again. [0, 1, 2, ..., 98, 99, 0, 1, 2, ...]
I just thought I explain it for those who are curious beginners. If it is inappropiate, I apologize.