H
Heat4Life
Guest
I am currently learning GML and I wonder what is the "max" code here... Please Explain... Thanks
Welcome to the GMC!
http://docs.yoyogames.com/source/dadiospice/002_reference/maths/real valued functions/max.html
If that is not what you want, please go into detail about what you are looking for. ^^'
Okay awesome Thanks Aura!Glad I could help :3
Since the query has been answered, you'd perhaps want to set the status of the topic as solved. To do that, go to Edit Title/Thread Tools >> Edit Title >> Set the topic prefix to Solved.
speed = max(speed - 0.01, 0);
How about this: speed = max(speed - 0.01, 0);it returns the largest value of the tested argument in it. IE:
a=2 b=5 c=-1
g=max(a,b,c)
g equals 5
speed -= 0.01;
if (speed < 0) {
speed = 0;
}
Well, I created a Spaceship game and I want to reduce the speed when aren't holding the key and this code works... But you said It returns the Highest Value and It will just set it to 0 because 0 is more higher... how did It reduce the speed then with this code speed = max(speed - 0.01, 0); ?!that will just set the speed ot zero.
https://forum.yoyogames.com/index.p...gs-2nd-tutorial-gamemaker-for-begginers.3841/
https://forum.yoyogames.com/index.php?threads/max.3523/
You already have two threads for this, so I'd suggest sticking to a single thread instead of creating one again.
Either way, I don't see what's so complicated in grasping that logic, unless you're way too young. I'll try to explain again.
Shaun used that code to avoid negative speed. The function would force the speed to remain at 0 while decreasing the speed by 0.01. The code basically does something similar to this:
Better now? ^^"Code:speed -= 0.01; if (speed < 0) { speed = 0; }
Correct, -0.01 is lower than 0, which is why the max function WILL NOT return -0.01. No one ever said it will return -0.01; we said it will return 0 when the result of speed-0.01 is negative.I thought what the max() function do is to return the highest Value... but -0.01 is lower than 0.. I don't get It, I don't know why...
I know how the Positive and Negative relate lmfao :l It's just I don't really get the explanation really... I feel like so stupid for the only guy here who can't understand a simple max() function -_-You are supposedly 17 years old but you don't even know how negative numbers, 0, and positive numbers all relate?
yeah... making tutorials using unorthodox methods just leads to this. imagine how much less confused he would be if this was just friction=-.01 lol. brevity is the soul of witt, dont do more than you have to.I updated my post.
@Roa He probably could just use the built-in function, but if he ever wants to implement his own friction mechanic, understanding how Shaun's works would help him. Shaun's friction and GM's friction are fundamentally nearly identical, just one is handled under the hood while the other needs to be coded by the user.
var slow = hspd - sign(hspd)/100;
hspd = slow * (sign(slow) == sign(hspd))
hspd = max(0,hspd-0.01);
Yeah I get it thanksWell the way he worded it, his post wouldn't do anything at all, as I said at the top of my last reply.