So, I play TrackMania, a car game where once you finished a run (so crossed the finish line) you can save your run to watch it later or add cool effect to it (We call it a "Replay").
I'm participating in a Project consisting of making as much replays as possible on the same level. The thing is that saving each replay by hand is very long, slow, and annoying after a while. So I want a script to save them for me.
The thing is that if I do twice the same time on a level, and use this Script to save my replay, it will Overwrite the previous one, which I don't want. So I want the script to check if the Replay name already exist, and if yes, the script add a number to it and then save the replay, so that way, it doesn't overwrite. Yay.
Luckily, I've participating in the Same project in the past, but on an other version of the game called ManiaPlanet (newer), and someone made a script using AHK for this newer game, and works just fine.
Now, the problem come when I want to change it to fit the older game, TrackMania :
In ManiaPlanet, the field where the ReplayName (editable) is written, you can select the text and then replace it. In TrackMania, however, you can't.
The script, to check if the Replay File already exist, use "copyboard", and ^c, ^a, ^v. But in TrackMania, as you can't select, it doesn't work.
So my question is : How else can I verify the Replay name and if necessary add a Number to it
Consider I'm really just a beginner in AHK scripting. I saw a command called "ControlGetText" but I don't understand it.
If I manage to get help on that point, a deeper help on the whole script would be much appreciated. I'm now gonna show you the working script :
Code: Select all
; This script is designed for ManiaPlanet
; It binds two keys in the game:
; M: Saves the replay and starts a new run
; N: Saves the replay but stays in the replay mode
;
; Both keys should only be pressed when the game is in replay mode.
; Customizable stuff. Change delay between key presses if it is too fast or
; change the hotkeys
ReplayDir = %UserProfile%\Documents\ManiaPlanet\Replays\Replays
DefaultDelay = 25
#IfWinActive, ahk_exe ManiaPlanet.exe
m::QuickSave(true)
#IfWinActive, ahk_exe ManiaPlanet.exe
n::QuickSave(false)
; Actual code
; Do not edit unless you know what you are doing!
#SingleInstance
; Saves the replay. Also adds a number at the end if the replay already exits.
; Parameter defines behavior whether it should just start a new replay or not
QuickSave(quick)
{
Global ReplayDir, DefaultDelay
CoordMode, Mouse, Screen
SetKeyDelay, DefaultDelay, 1
SetMouseDelay, 0
; Every comment below this point is wrote by me, not by the script author.
MouseMove, A_ScreenWidth / 2, (A_ScreenHeight / 2) + 260, 0
; This is moving the cursor basing on the window size ; But this also needs to be changed as the window is diffrent for trackMania.
Send, b ; This line is used to make all the Replay button, Including Save button, appear.
Send, {Left}
Send, {Enter} ; This is pressing Left and Enter key to select the Save button and click it. However the path is diffrent on TrackMania : Left, left, Down, Enter.
Click
MouseMove, A_ScreenWidth / 2, (A_ScreenHeight / 2) + 310, 0
; This is moving the cursor basing on the window size ; But this also needs to be changed as the window is diffrent for trackMania.
Send, {End}
Send, ^a
Send, ^c
IfExist, %ReplayDir%\%clipboard%.Replay.Gbx
{
BaseName = %clipboard%
BaseNameOrig = %BaseName%
count = 2
Loop
{
BaseName = %BaseNameOrig%_%count%
IfNotExist, %ReplayDir%\%BaseName%.Replay.Gbx
Break
count := count + 1
}
clipboard = %BaseName%
Send, ^v
}
Click
Send, {Enter}
Sleep, DefaultDelay * 4
if (quick)
count = 3
else
count = 1
Loop %count%
Send, {Enter}
}