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 


How to use MemoryRecord.OnActive

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Wed Jul 06, 2016 2:47 pm    Post subject: How to use MemoryRecord.OnActive Reply with quote

OnActivate: function(memoryrecord,before,currentstate):boolean


I am able to assign a function on Cheat Record Activate however i dont understand how to use the states. Adding states to the functions(....STATE...) causes LUA error. When the Record is activated it does not "check".

If someone could explain how the syntax works with an example please. TY

_________________
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4291

PostPosted: Wed Jul 06, 2016 3:19 pm    Post subject: Reply with quote

main.lua:
Quote:
OnActivate: function(memoryrecord,before,currentstate):boolean - The function to call when the memoryrecord will change (or changed) Active to true. If before is true, not returning true will cause the activation to stop.
  • memoryrecord - the memoryrecord that triggered this OnActivate event
  • before - boolean indicating if this function is being called before the memoryrecord has been activated (true) or after (false)
  • currentstate - boolean indicating the current state of the Active property of the memory record
  • return value - boolean indicating if the script should continue to attempt to activate (only relevant when before == true)
The second and third parameters are superfluous since they can be derived from the Active property of the memoryrecord.

AA script:
Code:
{$lua}
[ENABLE]
print("enabled")
[DISABLE]
print("disabled")

Lua script:
Code:
getAddressList()[0].OnActivate = function(memrec, before, currentstate)
  print(tostring(before), tostring(currentstate))
  return true
end

Output after enabling and disabling the AA script:
Code:
true false
enabled
false true
disabled

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Wed Jul 06, 2016 3:37 pm    Post subject: Reply with quote

TY for the fast the response Parkour by why is it executing the function twice.
_________________
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4291

PostPosted: Wed Jul 06, 2016 3:44 pm    Post subject: Reply with quote

The first time is to check if the game and/or CE are in the right state for the memory record to be activated, while the second is for you to react to it being activated (e.g. set the value of another memory record).
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Wed Jul 06, 2016 3:49 pm    Post subject: Reply with quote

Code:
global events
  function onMemRecPreExecute(memoryrecord, newstate BOOLEAN):
    If above function is defined it will be called before action* has been performed.
    Active property is about to change to newState.
 
  function onMemRecPostExecute(memoryrecord, newState BOOLEAN, succeeded BOOLEAN):
    If above function is defined it will be called after action*.
    Active property was supposed to change to newState.
    If 'succeeded' is true it means that Active state has changed and is newState.


So am I to assume that the CODE above is being called on the "OnActivate" function. Just curious as this seems to be quite complicated for "OnActivate" function.

_________________
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4291

PostPosted: Wed Jul 06, 2016 4:04 pm    Post subject: This post has 1 review(s) Reply with quote

No.
Lua script:
Code:
function onMemRecPreExecute(memrec, newstate)
  print("global pre")
  print(tostring(newstate))
end

function onMemRecPostExecute(memrec, newstate, succeeded)
  print("global post")
  print(tostring(newstate), tostring(succeeded))
end

getAddressList()[0].OnActivate = function(memrec, before, currentstate)
  print("local")
  print(tostring(before), tostring(currentstate))
  return true
end

Output w/ same AA script:
Code:
global pre    -- global pre-execute first called
true
local         -- local pre-execute called
true false
enabled       -- script successfully enabled
global post   -- global post-execute called
true true
local         -- local post-execute called
false true
global pre    -- script disabled, global pre-execute called
false
disabled      -- script successfully disabled
global post   -- global post-execute called
false true

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
akumakuja28
Master Cheater
Reputation: 16

Joined: 28 Jun 2015
Posts: 432

PostPosted: Wed Jul 06, 2016 4:22 pm    Post subject: Reply with quote

Parkour Thank You. I gave you A rep. You have gone above & beyond what I was asking for. No more Timer to check 4 table pointer entries anymore. TY again. This Helped ALOT.
_________________
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: Tue Jul 12, 2016 10:05 am    Post subject: Reply with quote

from CE source code, simplified:
Code:
  TMemoryRecord=class
  private
    ...
    ...
    fActive: boolean;
    ...
    ...
  end;



procedure TMemoryRecord.setActive(state: boolean);
begin

  // note; self if TMemoryRecord object


  // PRE EXECUTE START

  //6.5+
  LUA_functioncall('onMemRecPreExecute',[self, state]);  // global

  //6.1+

  // local, before (aka pre execute)
  if state then     if not fonActivate(self, true, fActive) then exit; //do not activate if it returns false
  if not state then if not fonDeactivate(self, true, fActive) then exit; //do not deactivate if it returns false

  // PRE EXECUTE END




  if "AA script" then
    begin
      autoassembleit() // "enable section" when state=true, "disable section" when state=false
      if "autoasseble succeded" then fActive:=state;
    end
  else if "value freeze/unfreeze" then
    begin
      if state and cannotfreeze then begin fActive:=false; exit; end;
      fActive:=state;
    end
  else if "anythingelse" then fActive:=state;




  // POST EXECUTE START
  //6.5+
  LUA_functioncall('onMemRecPostExecute',[self, state, fActive=state]);  //global

  //6.1+

  // local, after (aka post execute)
  if state then fonActivate(self, false, fActive); //activated , after
  if not state then fonDeactivate(self, false, fActive); //deactivated , after
  // POST EXECUTE END
end;






PS: I'm glad that someone finds "my pull request" helpful.

_________________
Back to top
View user's profile Send private message 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