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 


Lua script for check if the file exists.[solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
poppyko
How do I cheat?
Reputation: 0

Joined: 05 Sep 2021
Posts: 2

PostPosted: Sun Sep 05, 2021 6:47 am    Post subject: Lua script for check if the file exists.[solved] Reply with quote

I want to check if a certain file(setting.txt) is exist when I run an exe, but I can't run it correctly. Sad
The script looks like this.

What I want to do :if there is a setting.txt file, start it, if not, bring up a dialog and exit.
It works fine with the execute script on cheatengine, but not with the standalone exe.

Code:
--TRAINERGENERATORSTART--
--hideAllCEWindows()
function file_check(file_name)
  local file_found=io.open(file_name, "r")

  if file_found==nil then
    file_found=file_name .. " ... Error - setting file missing"
    closeCE()
  else
    file_found=file_name .. " ... found"
  end
  return file_found
end
print(file_check("setting.txt"))
RequiredCEVersion=7.3
if (getCEVersion==nil) or (getCEVersion()<RequiredCEVersion) then
  messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
  closeCE()
end

function onPostHotkey0(Hotkey)
  --Executed after the "toggle*" cheat got executed
  local memrec=Hotkey.Owner
  local isActive=memrec.Active --get the state after the hotkey got triggered
  CETrainer.CHEAT0.setActive(isActive) --gui update, nothing else
  if gPlaySoundOnAction then
    if isActive then
      playSound(gActivateSound)
    else
      playSound(gDeactivateSound)
    end
  end
end


Last edited by poppyko on Sun Sep 05, 2021 8:30 am; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Sep 05, 2021 7:00 am    Post subject: Reply with quote

Where is the file located? Inside the trainer package or next to the trainer exe ?

if inside the trainer package use getCheatEngineDir. if next to tbe trainer exe, use TrainerOrigin

_________________
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
poppyko
How do I cheat?
Reputation: 0

Joined: 05 Sep 2021
Posts: 2

PostPosted: Sun Sep 05, 2021 8:29 am    Post subject: Reply with quote

Yes, it is in the same folder as trainer.exe, so I was able to solve the problem by using TrainerOrigin. Very Happy

Thank you for your quick answer!
I sleep well.
Back to top
View user's profile Send private message
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