Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
3 registered members (TedMar, AndrewAMD, fairtrader), 578 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How do I use Min & Max?! HELP ME PLEASE! #8552
03/25/02 08:07
03/25/02 08:07

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



How can I limit a variable using these functions?
Help Please!

Glome

Re: How do I use Min & Max?! HELP ME PLEASE! #8553
03/25/02 19:43
03/25/02 19:43

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



result=min(10, 20); will use always the smaller value 10
result=max(10,20); will use 20 insted

you can combine that to:
result=max(0, min(20,10)); first it will chose the min of (20,10) =10 and then it will chose the maximum of (0,10) =10 result=10;

Re: How do I use Min & Max?! HELP ME PLEASE! #8554
03/26/02 02:49
03/26/02 02:49

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



Um, that's a little confusing. Could you explain it to me a little more please?

Glome

Re: How do I use Min & Max?! HELP ME PLEASE! #8555
03/26/02 03:00
03/26/02 03:00
Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
Phantom88 Offline
Expert
Phantom88  Offline
Expert

Joined: Oct 2001
Posts: 1,407
Helsinki, Finland
result=max(0, min(result,10)); Now result is limited to 1-10.

~Phantom88~


Programmer, Gamer ICQ #: 157485106 | Xfire: Phantom1988 | MSN: lauri_andler@hotmail.com | AIM: FinPhantom | YAHOO: FinPhantom
Re: How do I use Min & Max?! HELP ME PLEASE! #8556
03/26/02 03:11
03/26/02 03:11

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



Ok, thanks!

Re: How do I use Min & Max?! HELP ME PLEASE! #8557
03/26/02 03:23
03/26/02 03:23

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



"min" compares two variables (numbers) and will return whichever one is smaller (the minimum).

thing = min(noise, 10);

If noise is 11, thing will be 10 (it's smaller)
If noise is 9, thing will be 9 (it's smaller)

"max" works the opposite way:

thing = max(noise, 10);

If noise is 11, thing will be 11 (it's bigger)
If noise is 9, thing will be 10 (it's bigger)

min sets the upper limit for the value of a variable.
max sets the lower limit for the value of a variable.

Suppose you have a tachometer, and as long as the engine is running, you want to show the RPM of the engine. But you don't want it to go below 500 RPM (idle) even when you are backing up. (Negative speed could result in a negative RPM calculation.) Or, if you are stopped (car speed is zero), but the engine is still running, your calculations could result in a zero engine speed.
The solution is very simple:
RPM = max(RPM,500);

The RPM will then be whichever is bigger, the actual RPM, or 500. So even if the real RPM goes below idle, to zero, or even negative, your tachometer will never show below 500.
(You will need to force it to zero somewhere else in your code, if you do shut off the engine.)

The example in the manual is just a tricky combination of the two. The second variable has been replaced by substituting the other min/max function. (Pick some numbers, and work through it by hand, to understand it better. Start with the embedded function.)

One gotcha - the manual is missing the last parenthesis, on the right. If you use the example, exactly as it is, you will get an error. Just add the missing right parenthesis, and it will work fine!

Hope this helps!

Re: How do I use Min & Max?! HELP ME PLEASE! #8558
04/04/02 14:28
04/04/02 14:28

A
Anonymous OP
Unregistered
Anonymous OP
Unregistered
A



Thanks!

Glome [Big Grin]


Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1