Get the best time of 4 players
Hi! I want to get the best time of the 4 players. What is the best way to do that? Each player has their own game time variable. When all the players finished the level, I use get time and wire then into a calculator. The problem is that the calculator has only 2 inputs A and B. I have 4 variables I need to compare to get the best time. And the player with the best time will have a text displayed. For example: PLAYER 2 WON! I'm so stuck in this now. Just wonder if someone can help me a bit? Just point me in the right direction! Thanks! 😊
-
There are a number of possible solutions.
Off the top of my head, one relatively simple method that's easy to understand would be to set up a few calculators.
Use the calculator's 'Minimum of' function to output the minimum of two inputs.
Then you'd check
* [Minimum of (P1 vs P2)]
* [Minimum of (P3 vs P4)]
Then you'd take these two outputs to a third calculator to work out the minimum of both of these - and that's the best time.
Then you could test each of the four players to see which of them has a time that is equal to the best time.
-
Another way that's more setup, but a fun thing to play with is...
You can find the highest positive value of many inputs by wiring them all into one setting, or a node. It should use the "overwrite" wire-blend mode, and will give you the value furthest from 0.
If you want the inverse of that... subtract each from some large number. So the higher the input, the lower the output. And the highest result will then be for the lowest input number. As in... 2000 - (8) = 1992. 2000 - (5) = 1995. Wire those into the same node, and 1995 is further from 0, so it'll output 1995. Subtract that from 2000 again, and it'll give you the original number of the *lowest* input. 2000 - 1995 = (5). And now you've got the lowest number.
Then you could compare each real time of each player to that "lowest" time.
Probably wasteful on thermo though XD
-
A smart way of doing it would be to use exclusive gates. For each player, have an ex-gate. Name the ex-gates all the same.
Set the "priority" setting to -1. Wire the time into the "priority"; it should automatically use the "modulate" wire-blend mode, which multiples the input (time) by the setting (-1). Meaning if the time is higher, the priority will be lower.
Wire a single switch or something into inputs of all the ex-gates so they try to "open." Only the gate with the highest priority will be allowed to open. The gate has an "active" output for when it's open. So the player whose ex-gate is open has the lowest time.
-
Thank you both for the answers!
QuietlyWrong:
This is what I did after trying and trying and trying. 😀
It looks like it works now.But I had to change the logic a bit according if it's 2, 3 or 4 players.
TAPgiles:
Your way sound more difficult. It could be funny to experiment a bit with other ways, but I think I go for the way that works for me. 😀 -
Good to hear it's working for you! :)
I like the Exclusive Gate as a smart solution. But they're complicated gadgets!
For dealing with 2, 3 or 4 players I'd just give each one a default time of, say, a million seconds if they are absent - then hopefully they'll never be the winner. Assuming the game/race doesn't take twelve days to finish! ;)
Edit: oops, I just remembered that I once made a chip whose job is to convert zero or 'off' values into a different default. So if a value is zero, it gets changed (to a million, for this example), but if it's anything else, it comes out unchanged. It might be useful in this case!
-
Ex-gates are complicated... if you use their complicated features. And very simple when you use their simple features. ;p
-
Here's how I would do it with ex-gates in 1 minute: https://youtu.be/-SSQwFJK4Bw ;P
0 time will be ignored. So no false-positives, and you can have fewer players and the logic still works. You can have this stuff in their own players also.
(Just trying to show ex-gates aren't as scary as they look :D)
-
I will continue on this post instead of making a new one.
I got it to work to find the best time, but how can I find the 2nd best and the 3rd? 4th is easy since it's just using the maximum instead of minimum.
It was harder than I thought.
Please sign in to leave a comment.