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 


[Help] Count from 1 address

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Sat Jul 31, 2021 4:07 am    Post subject: [Help] Count from 1 address Reply with quote

Hello there,
Let say i have address who change from 0 to 1 repeatedly, what i am asking is is there any way to make a count from it? something like if 0 then count + 1 till 100 and then stop counting. and put count the edittext. Any example would be good to me

{$lua}
local counter = 0

function output(t1)
counter = counter + 1
setProperty(UDF1.CEEdit1,'Text',counter)
end

function enableFunction()
t1 = createTimer(nil, true)
t1.Interval = 1000
t1.OnTimer = output
end

function disableFunction()
t1.setEnabled = false
t1.destroy()
t1 = nil
end

[ENABLE]
enableFunction()


[DISABLE]
disableFunction()

on that script how i stop counting after 10? rather than disabling manually
thanks in advance
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Jul 31, 2021 7:32 am    Post subject: Reply with quote

I guess you'll want to close the script when the timer dies.

Code:
{$lua}
if syntaxcheck then return end

local counter = 0


if t1 then t1.Destroy() t1=nil end

t1 = createTimer()
t1.Interval = 1000
t1.Enabled = false

function disableFunction()
if t1 then t1.Destroy() t1=nil end
end

function output()
counter = tonumber(counter) + 1
print("counter: "..counter)
if counter==10 then
--setProperty(UDF1.CEEdit1,'Text',counter)
disableFunction()
sct1=getAddressList().getMemoryRecordByDescription("YouDesc")
sct1.Active=false
print("t1.Enabled=false\nScript.Active=false")
end
end


function enableFunction()
t1.OnTimer = output
t1.Enabled = true
end

[ENABLE]
enableFunction()


[DISABLE]
disableFunction()
Back to top
View user's profile Send private message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Sat Jul 31, 2021 3:04 pm    Post subject: Reply with quote

TY works fine with me
Back to top
View user's profile Send private message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Mon Aug 02, 2021 6:43 am    Post subject: Reply with quote

the script you are wrote is stoping the timer, what i need is counting the value of the address everytime the address change the value from 0 to 1 i mean if value = 1 then count as 1+1 and soo on after 100 then the value that store on the editbox will use as script stoper
thanks in advance
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Mon Aug 02, 2021 8:42 am    Post subject: Reply with quote

I'm starting to get confused about the problem.
The main code below will automatically change the value between 0-1 and the credit will increase by + 1 on each change. (Every time the default value is 1, the credit will increase by +1)
If you don't want the value to change and you just want the main code to follow, use this edit:

Code:
function output()
if YouValue.Value=="1" then
  if valueIndex==1 then
  valueIndex=0
  --- >>> YouValue.Value=0
  --print("Index: "..valueIndex.." - counter: "..counter.." - Value: "..YouValue.Value)

  end
  else
  if YouValue.Value=="0" then
  counter = tonumber(counter) + 1
  valueIndex=1
  --- >>> YouValue.Value=1
  print("Index: "..valueIndex.." - counter: "..counter.." - Value: "..YouValue.Value)

  end
end
if counter==10 then
--setProperty(UDF1.CEEdit1,'Text',counter)
disableFunction()
sct1=getAddressList().getMemoryRecordByDescription("YouDesc")
sct1.Active=false
print("t1.Enabled=false\nScript.Active=false")
end
end


Main Code:
Code:
{$lua}
if syntaxcheck then return end

local counter = 0
local valueIndex=1
local YouValue=getAddressList().getMemoryRecordByDescription("YouValue (0-1)")

if t1 then t1.Destroy() t1=nil end

t1 = createTimer()
t1.Interval = 1000
t1.Enabled = false

function disableFunction()
if t1 then t1.Destroy() t1=nil end
counter = 0
valueIndex=1
end

function output()
if YouValue.Value=="1" then
  if valueIndex==1 then
  valueIndex=0
  YouValue.Value=0
  --print("Index: "..valueIndex.." - counter: "..counter.." - Value: "..YouValue.Value)

  end
  else
  if YouValue.Value=="0" then
  counter = tonumber(counter) + 1
  valueIndex=1
  YouValue.Value=1
  print("Index: "..valueIndex.." - counter: "..counter.." - Value: "..YouValue.Value)

  end
end
if counter==10 then
--setProperty(UDF1.CEEdit1,'Text',counter)
disableFunction()
sct1=getAddressList().getMemoryRecordByDescription("YouDesc")
sct1.Active=false
print("t1.Enabled=false\nScript.Active=false")
end
end


function enableFunction()

t1.OnTimer = output
t1.Enabled = true
end

[ENABLE]
enableFunction()


[DISABLE]
disableFunction()


And yes, I set a target of 10 seconds to see the short result..
Here, write the credit that the follow-up should end;

Code:
if counter==10 then
--setProperty(UDF1.CEEdit1,'Text',counter)
disableFunction()
sct1=getAddressList().getMemoryRecordByDescription("YouDesc")
sct1.Active=false
print("t1.Enabled=false\nScript.Active=false")
end


or 100 counter stop:

Code:
if counter==100 then
--setProperty(UDF1.CEEdit1,'Text',counter)
disableFunction()
sct1=getAddressList().getMemoryRecordByDescription("YouDesc")
sct1.Active=false
print("t1.Enabled=false\nScript.Active=false")
end
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Mon Aug 02, 2021 8:58 am    Post subject: Reply with quote

You can compare the value of the address by retrieving the value of the memory record.

Code:

local al = getAddressList()
local mr = al.getMemoryRecordByDescription('[Address Description here]') -- Note: Without square brackets

if mr ~= nil then
   if mr.Value == 1 then
      counter = counter + 1
      if counter == 100 then
        -- disable timer
        -- set value of edit back to 0 for the loop to start all over again
        -- and restart the timer by calling enableFunction() again if required
      end
   end
end
Back to top
View user's profile Send private message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Mon Aug 02, 2021 9:45 am    Post subject: Reply with quote

i manage my self writing sript like bellow
counter = AL.getMemoryRecordByDescription('click (1)')

function output(tb0)
for i = 1, 100 do
if counter.value == 1 then
count = counter + 1
setProperty(UDF2.CEEdit1,'Text',count)
end
end

local b0 = UDF2.CEToggleBox1

function UDF2_CEToggleBox1Change(sender)
if (b0.State == 1) then
tb0 = createTimer(nil, true)
tb0.Interval = 1000
tb0.OnTimer = output
else
tb0.setEnabled = false
tb0.destroy()
tb0 = nil
end
end
end

but the sript wont show in CEEdit1
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Mon Aug 02, 2021 10:39 am    Post subject: Reply with quote

Code:
UDF2.CEEdit1.Text=('Text '..count)


or

Code:
control_setCaption(UDF2.CEEdit,'Text '..count)



Code:
function output(tb0)
for i = 1, 100 do
if counter.value == 1 then
count = counter + 1
setProperty(UDF2.CEEdit1,'Text',count)
end
end
end


or
Code:

local count=0

function output() --function output(tb0)
if count~=100 then
if counter.value == 1 then
count = counter + 1 --count = tonumber(counter) + 1
UDF2.CEEdit1.Text=('Text '..count)
end
end
end
Back to top
View user's profile Send private message
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Mon Aug 02, 2021 12:29 pm    Post subject: Reply with quote

thank you that solved the problem
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