View previous topic :: View next topic |
Author |
Message |
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Tue Nov 22, 2011 1:22 pm Post subject: Log data to file from LUA |
|
|
Hi,
i just wanted to know if it is good or if there is a better way for logging data to file..
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Tue Nov 22, 2011 1:32 pm Post subject: |
|
|
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 |
|
|
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Wed Nov 23, 2011 5:16 pm Post subject: |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Wed Nov 23, 2011 6:23 pm Post subject: |
|
|
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 |
|
|
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Sun Dec 18, 2011 1:14 pm Post subject: |
|
|
Hello,
here i come again
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Sun Dec 18, 2011 1:58 pm Post subject: |
|
|
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 |
|
|
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Sun Dec 18, 2011 5:02 pm Post subject: |
|
|
Ok you are right, LUA need a full path. thank you
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 |
|
|
atom0s Moderator Reputation: 198
Joined: 25 Jan 2006 Posts: 8517 Location: 127.0.0.1
|
|
Back to top |
|
|
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Mon Dec 19, 2011 2:22 am Post subject: |
|
|
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 |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Mon Dec 19, 2011 4:46 pm Post subject: |
|
|
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 |
|
|
hiring_dude Newbie cheater Reputation: 0
Joined: 28 Nov 2010 Posts: 20
|
Posted: Tue Dec 20, 2011 4:39 pm Post subject: |
|
|
Working great !!!
thank you !
|
|
Back to top |
|
|
|