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 trigger a function call on table value edit?

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

Joined: 04 May 2016
Posts: 717

PostPosted: Thu Jun 16, 2016 3:18 pm    Post subject: How to trigger a function call on table value edit? Reply with quote

I have a script im working on that receives a game time in seconds
I create three addresses: Days, Minutes, Hours
I want to write to the original memory location the new accumulated seconds value when the user edits the days, minutes, or hours field.

I am using a timer (100ms) to update the addresses with the current time
I am thinking about using a timer to "watch" the address for user intervention, but I would have to disable the second timer everytime the first timer wrote the values and then enable the second timer afterwards.
Is this the only way to do what I want?

AKA:

Days=3
Days will always =3 unless it is changed by the first timer to 4
If user changes Days to 0, then there will be a difference, and we can write the new accumulated seconds to the memory address.

IF i disable the watch timer while the first timer updates from 3 to 4, it shouldn't trigger the second timer.

However, this is old school because there should be some sort of onEvent function to call for when a user interacts with the table.

From main.lua
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.
   
    newState and succeeded are read only.
 
    *action can be: running auto assembler script (ENABLE or DISABLE section), freezing and unfreezing.


But this is the only onEvent I could find, and it only works for an enable/disable/freeze/unfreeze, not a user edit.

Am i missing something or do i need to implement a two timer system?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Thu Jun 16, 2016 5:22 pm    Post subject: Reply with quote

Your timer is just constantly writing the game timer (freezing)?

If the user changes the days, hours, or minutes, why doesn't your timer use the new value in those records?
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Fri Jun 17, 2016 10:16 am    Post subject: Reply with quote

The game timer has a single address which holds number of seconds since world initialized.

I can parse that into readible data using my first timer. (Days, Hours, Minutes). I created these addresses myself in asm using alloc/registersymbol.

My timer constantly reads the number of seconds, parses them into days, hours, minutes, and writes those values for display in the table.

If the game had these fields, i would simply display them to the user, and their edits would reflect in the game.

The game does not have these fields, I would like to allow for a user to edit the table, and once edited an onEvent trigger to my function call for writing the game time by adding the days, hours, and minutes together and setting that into the game's address for total seconds.

It appears that the only onEvent code in the game is for enable/disable of ASM script, or freeze/unfreeze of code.

My request is if I'm missing something in the main.lua or if the only solution is my two timer example in the original post.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 55

Joined: 01 Oct 2008
Posts: 942

PostPosted: Fri Jun 17, 2016 10:53 am    Post subject: Reply with quote

Yes, onMemRec(Pre|Post)Execute @ Global and On(Dea|A)ctivate @ Memory Record Class are specify for events of activate/deactivate only, they don't detect value change by user input that happened not on freeze/unfreeze event.

May provide some custom ui for user intervention.

Some ui (eg Edit Box) has the OnChange Event Handler (continue fire for every edit action).
Most control ui have the OnEnter/OnExit (focus) handler,ie. start and end editing state, may prevent continue fire for every edit action.

bye~

_________________
- Retarded.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Jun 17, 2016 1:34 pm    Post subject: Reply with quote

Duplicate your days, hours, and minutes variables and do not present this set to the user.
During your code that calculates the new values, first check to see if the user values still match your duplicate values.
If not, then don't bother updating them in your code this go around.
Instead, use the user values to calculate the new elapsed timer value and update it.
Be sure to update your duplicate values at this time so they match the user values on the next go.
If the two sets originally matched, just be sure to update them both together to match the new game time.
Back to top
View user's profile Send private message
cooleko
Grandmaster Cheater
Reputation: 11

Joined: 04 May 2016
Posts: 717

PostPosted: Fri Jun 17, 2016 1:40 pm    Post subject: Reply with quote

That is a much cleaner way to accomplish my goal, thanks!
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