I'm trying to set up a very basic scoreboard system which should work on every Windows machine without having to install anything (like Python). I'm not sure if a batch file is the way to go there, since it's really outdated, but I just went for it here. This is what I'm trying to do:
- Have a script that lets the operator enter a name and a score
- Sort all of the scores
- Export the top 5 players as a separate txt file (e.g. PointsTopPlayer1.txt, NameTopPlayer1.txt, PointsTopPlayer2.txt, NameTopPlayer2.txt, etc.)
This is what I have so far. A batch-script that let's the user enter a name and some points.
:start
@echo off
cls
echo Please enter data
echo.
set /p _player=name:
:inputpoints
set /p _points=points:
echo %_points%| findstr /r "^[1-9][0-9]*$">nul
if not %errorlevel% equ 0 goto invalid
(echo=%_points%,%_player%)>> data.txt
echo Data saved.
timeout 2 > nul
goto start
:invalid
echo Please enter a valid number.
timeout 1 > nul
goto inputpoints
Now my next guess would be to add a line in the script that sorts the data.txt list, which currently looks like this:
500,Bob
390,Thomas
650,Sam
100,Nick
20,Olivia
Altough it looks like there is no real way to sort numbers except for the sort command, which is not working in this case, because it sorts the numbers alphabetically, which puts 100 before 20. I saw this script online, but I have no clue how to use it to be honest. Next step would be exporting all of the data in seperate files (for the top 5 players), which is something I have no idea how to pull off.
Any ideas appreciated!