Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Error printing trainer name!

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1261

PostPosted: Tue Feb 13, 2024 10:55 am    Post subject: Error printing trainer name! Reply with quote

@DarkByte, the code below works fine with ".CT".
However, when I try it with ".CETRAINER", it gives a loading error for the table and the Trainer does not open.

What I'm trying to do is get the filename of the current Trainer (cetrainer).

I would appreciate it if you could please try it and give me some advice. Thanks.

Code:
if form11 then form11.destroy() form11=nil end

form11 = createForm()
form11.Position = poDesktopCenter
form11.Popupmode = 0
form11.Width = 320
form11.Height = 240
form11.ShowInTaskBar="stAlways"

mf23 = MainForm
local sd2, od2 = mf23.SaveDialog1, mf23.OpenDialog1
filefullpath = sd2.Filename or od2.Filename or ""

  if filefullpath~=nil or filefullpath~="" then
   print("filefullpath-1: "..filefullpath)
  else
   saveTable()
   sd2 = mf23.SaveDialog1
   filefullpath = sd2.Filename
   print("filefullpath-1: "..filefullpath)
  end

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25300
Location: The netherlands

PostPosted: Tue Feb 13, 2024 11:22 am    Post subject: Reply with quote

use the variable TrainerOrigin to get the path of the .cetrainer
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 32

Joined: 16 Feb 2017
Posts: 1261

PostPosted: Tue Feb 13, 2024 11:45 am    Post subject: Reply with quote

No. What I want is the Trainer filename.
"TrainerOrigin" gives the file path where the Trainer is registered.
If there is more than one Trainer in the folder, it is difficult to find the Trainer name used.


EDITING :

I apologize. There is something I missed.

When I left a delayed trigger (Timer) everything worked fine.

I am sharing the code for archive purposes:

Code snippet that corrects the Trainer name at every startup;

Code:
if form11 then form11.destroy() form11=nil end

form11 = createForm()
form11.Position = poDesktopCenter
form11.Popupmode = 0
form11.Width = 320
form11.Height = 240
form11.ShowInTaskBar="stAlways"

function EditTrainerName(newName)
   saveTable()
mf23 = getMainForm()
sd2 = mf23.SaveDialog1
od2 = mf23.OpenDialog1
sd2.DefaultExt = ".cetrainer" or ".CETRAINER"
filefullpath = sd2.FileName or od2.FileName
local filename = ""
local testCheck1 = 0
ttName1=createTimer(MainForm) ttName1.Interval=2000

local function returnFileName(path,ops)
local restt1 = ""
  if ops==1 then
   restt1 = path:match("\\([^\\]+)$")
  elseif ops==2 then
   restt1 = path:match("(.*)\\")
  end
 return restt1
end


  ttName1.OnTimer=function()
   saveTable()
   filefullpath = sd2.FileName or od2.FileName
   --print("filefullpath-2: "..filefullpath)
   path = returnFileName(filefullpath,2) -- or path = TrainerOrigin
   path = path.."\\"
   --print("path-2: "..path)
   filename = returnFileName(filefullpath,1)
   --print("filename: "..filename)
    if filename~=newName then
     os.rename(path..filename, path..newName)
     testCheck1 = 1
    end
    if testCheck1==1 then
     ttName1.Enabled=false
     nm1 = newName:match("(.*)%.")
     showMessage([[Trainer has been updated to the "]]..nm1..[[" version!]])
    else
     ttName1.Enabled=false
    end
  end

  ttName1.Enabled=true
end

form11.OnClose=function()
closeCE()
return cafree
end

-- use
EditTrainerName("myGameTrainer-V002.cetrainer")

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites