Checking if a Filename already Exist Topic is solved

Ask gaming related questions (AHK v1.1 and older)
KyaCeption

Checking if a Filename already Exist  Topic is solved

17 Apr 2018, 20:13

Hi guys :wave:

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}
}
There it is, any help will be much, much appreciated, thanks for reading and a Huge thanks to whoever will try to help me :D Cya, soon I hope :wink:
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Checking if a Filename already Exist

19 Apr 2018, 12:45

Whilst you cannot control the name it saves as, if you could find out somehow what name it was *about* to save as, you could maybe rename the file that was going to be overwritten?
Failing that, you could maybe have an AHK script which monitors the folder, and when it sees a new file appear, it immediately renames it (eg it could add a date to the end), then the game could never overwrite anything.
But this may well need a completely different script than the one you have.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 57 guests