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 enable and disable a function in Lua?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sat Feb 20, 2016 4:27 pm    Post subject: How to enable and disable a function in Lua? Reply with quote

I want to enable or disable a function when I need it. Is there a way to do that? Something like call EnableFunction(XXX)? Thanks a lot.
Back to top
View user's profile Send private message
Daijobu
Master Cheater
Reputation: 13

Joined: 05 Feb 2013
Posts: 301
Location: the Netherlands

PostPosted: Sat Feb 20, 2016 5:13 pm    Post subject: Reply with quote

Create a variable in memory and use a AA script to set that variable and check against it.

AutoAssemble example:

Code:
[ENABLE]
globalalloc(myAllocatedVariable,1) --you can use this in your table

myAllocatedVariable:
db 1

[DISABLE]
myAllocatedVariable:
db 0

dealloc(myAllocatedVariable)



Lua Example:
Code:
local function myTimer(Sender)
  while readInteger('myAllocatedVariable') == 1 do
    myFunction() --execute function
    writeInteger('myAllocatedVariable',0) --disable, optional unless you want to loop it
  end
end

t=createTimer(Sender) --create timer 't',owner
timer_setInterval(t, 1000) --timer,milliseconds
timer_onTimer(t,myTimer) --timer,function
timer_setEnabled(t,true) --timer,boolean
--(still copied and pasta'd from Alice0725)


From main.lua
:

Code:
Timer Class : (Inheritance: Component->object)
createTimer(owner OPT, enabled OPT):
  Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned)
  Owner may be nil, but you will be responsible for destroying it instead of being the responsibility of the owner object)

properties
  Interval: integer - The number of milliseconds (1000=1 second) between executions
  Enabled: boolean
  OnTimer: function - The function to call when the timer triggers

methods
  getInterval()
  setInterval(interval) : Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second)
  getOnTimer()
  setOnTimer(function)
  getEnabled()
  setEnabled()boolean)

_________________
Scripts/tables from scratch. Relation to other scripts is coincidental. Use of posted code is credited properly.
Euro Truck Simulator 2 Backwards Compatible Cheat
American Truck Simulator Backwards Compatible Cheat
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sat Feb 20, 2016 8:08 pm    Post subject: Reply with quote

Daijobu wrote:
Create a variable in memory and use a AA script to set that variable and check against it.

AutoAssemble example:

Code:
[ENABLE]
globalalloc(myAllocatedVariable,1) --you can use this in your table

myAllocatedVariable:
db 1

[DISABLE]
myAllocatedVariable:
db 0

dealloc(myAllocatedVariable)



Lua Example:
Code:
local function myTimer(Sender)
  while readInteger('myAllocatedVariable') == 1 do
    myFunction() --execute function
    writeInteger('myAllocatedVariable',0) --disable, optional unless you want to loop it
  end
end

t=createTimer(Sender) --create timer 't',owner
timer_setInterval(t, 1000) --timer,milliseconds
timer_onTimer(t,myTimer) --timer,function
timer_setEnabled(t,true) --timer,boolean
--(still copied and pasta'd from Alice0725)


From main.lua
:

Code:
Timer Class : (Inheritance: Component->object)
createTimer(owner OPT, enabled OPT):
  Creates a timer object. If enabled is not given it will be enabled by default (will start as soon as an onTimer event has been assigned)
  Owner may be nil, but you will be responsible for destroying it instead of being the responsibility of the owner object)

properties
  Interval: integer - The number of milliseconds (1000=1 second) between executions
  Enabled: boolean
  OnTimer: function - The function to call when the timer triggers

methods
  getInterval()
  setInterval(interval) : Sets the speed on how often the timer should trigger. In milliseconds (1000=1 second)
  getOnTimer()
  setOnTimer(function)
  getEnabled()
  setEnabled()boolean)


Thanks a lot for the detailed answer. 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