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 


Log data to file from LUA

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Tue Nov 22, 2011 1:22 pm    Post subject: Log data to file from LUA Reply with quote

Hi,
i just wanted to know if it is good or if there is a better way for logging data to file.. Embarassed
i'm doing most of the processing/retreiving data to log through AA but i check from LUA with an infinite loop + sleep() if a flag symbol is set TRUE :


Code:

-------------------- simple log file test
function log_game_stats()
  f = io.open("log.txt","a+");
  f:write("hello world!\n");
  f:close();
end

while true do
  if (readBytes("logflag",1,false) == 1) then
      log_game_stats();
      writeBytes("logflag",0); -- raz
      print("log done");
    break
  else
    print("sleeping...  "..count);
    sleep(1000);
  end
end 
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Tue Nov 22, 2011 1:32 pm    Post subject: Reply with quote

An infinite loop is a bad idea unless you use 6.2's multithreading support because it will freeze ce completely until the logflag is finally set to 1)

I recommend you create a timer object that triggers every second and calls a function that checks if the log flag is set and if set write the log and destroy the timer (based on the break)

_________________
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
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Wed Nov 23, 2011 5:16 pm    Post subject: Reply with quote

right ! the createTimer work better. thank you !
btw i'm using hitting very often the "execute script" button..
is there a command line in lua for clearing the output automatically instead of manually file > clear output every time ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Wed Nov 23, 2011 6:23 pm    Post subject: Reply with quote

No, but I'll see if I can come up with something.

otherwise instead of using print create a form with a memo and write the output to there. (Just create the memo, and then rewrite the print function so it outputs to that memo instead)

_________________
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
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Sun Dec 18, 2011 1:14 pm    Post subject: Reply with quote

Hello,
here i come again Smile

i advanced a lot on my work but now i'm facing again this problem about writing data to disc :

Code:
function main()
  f = io.open("log_test.txt","a+");
  f:write("something to write on "..os.date().."\n");
  f:close();
  print("main executed");
end

main();


just this simple LUA function work normally in CE but creating simple cheat.exe from it fail without notice (no file created or writed)
am i missing something ?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Dec 18, 2011 1:58 pm    Post subject: Reply with quote

Try providing a full path to the file like [[c:\log_test.txt]]
The current working dir might not be writable

(and try using showMessage to see if it's actually executed. Not sure if I disabled print shows in standalone .exe's )

_________________
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
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Sun Dec 18, 2011 5:02 pm    Post subject: Reply with quote

Ok you are right, LUA need a full path. thank you Smile
but if try to get the current cheat.exe
but getCheatEngineDir() provide me a temp folder whereas it's just on the desktop :
D:\DOCUME~1\JIM\LOCALS~1\Temp\cetrainers\CET1EC.tmp\extracted\

it's a stupid question but how can i get current dir where the cheat.exe is located ???
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sun Dec 18, 2011 5:15 pm    Post subject: Reply with quote

hiring_dude wrote:
Ok you are right, LUA need a full path. thank you Smile
but if try to get the current cheat.exe
but getCheatEngineDir() provide me a temp folder whereas it's just on the desktop :
D:\DOCUME~1\JIM\LOCALS~1\Temp\cetrainers\CET1EC.tmp\extracted\

it's a stupid question but how can i get current dir where the cheat.exe is located ???


CE 6.x trainers are packed with the needed files to execute the trainer. When the trainer starts it unpacks the files to the %temp% folder for that user. So you will always get the temp path instead of the location the trainer itself is located at.

On a Windows XP based machine you can use os.getenv to obtain the desktop path like this:

Code:

local userDesktop = os.getenv("USERPROFILE") .. "\\Desktop";
print( userDesktop );

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Mon Dec 19, 2011 2:22 am    Post subject: Reply with quote

Wiccaan wrote:

CE 6.x trainers are packed with the needed files to execute the trainer. When the trainer starts it unpacks the files to the %temp% folder for that user. So you will always get the temp path instead of the location the trainer itself is located at.

On a Windows XP based machine you can use os.getenv to obtain the desktop path like this:

Code:

local userDesktop = os.getenv("USERPROFILE") .. "\\Desktop";
print( userDesktop );

Thank's Wiccaan, that's work.
But about this path.. it's disturbing me. If i want to make it clean, how can i get the log file automatically created in the same folder as the cheat.exe or gameAttached.exe ??
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Dec 19, 2011 4:46 pm    Post subject: Reply with quote

Edit:
I made new topic. Read here (modified standalonephase2.dat):
http://forum.cheatengine.org/viewtopic.php?t=545361



You need modified standalonephase2.dat and this:
Code:

function getTrainerRealPath()
local t
  local f = io.open("TrainerRealPath.txt", "r")
  if (f ~= nil) then
    t = f:read("*all")
    f:close()
  else
    t = nil
  end
  return t
end


MyPath = getTrainerRealPath() -- Trainer real path

if MyPath then
  respondfile = io.open(MyPath.."RESPOND.txt", "w")
  respondfile:write('GR8, it works\nOur path is: "'..MyPath..'"')
  respondfile:close()
end

function main()
 if MyPath then
  f = io.open(MyPath.."log_test.txt","a+")
  f:write("something to write on "..os.date().."\n")
  f:close()
  print("main executed")
 end
end

main()



(Click to enlarge)

It's my FarCry2 trainer, slightly modified - I only added above script and recreated it with modified standalonephase2.dat file. Files log_test.txt and RESPOND.txt are created after trainer launch.

_________________
Back to top
View user's profile Send private message MSN Messenger
hiring_dude
Newbie cheater
Reputation: 0

Joined: 28 Nov 2010
Posts: 20

PostPosted: Tue Dec 20, 2011 4:39 pm    Post subject: Reply with quote

Working great !!!
thank you !
Very Happy
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