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 


[ask] counter wont increased [solved]

 
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: Thu Jan 27, 2022 10:31 am    Post subject: [ask] counter wont increased [solved] Reply with quote

hello master, just want to ask why the function below doesnt increased the counter value? and the result always stay on 1
when the value of the address changed from 0 to 1 it should be increased the counter
Code:

hud= 1
counter = 0
IsIncreased = false
al = getAddressList()
mr = al.getMemoryRecordByDescription
foo = mr('infight')
function countme()
         if tonumber(foo.Value == hud) and
            IsIncreased == false
            then
               counter = tonumber(counter) + 1
               print('true')
               IsIncreased = true
              else
                    print('false')

end
end

thanks in advance


Last edited by icsmoke+ on Sun Jan 30, 2022 10:32 am; edited 1 time in total
Back to top
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Thu Jan 27, 2022 11:56 am    Post subject: This post has 1 review(s) Reply with quote


  1. Setting "mr" to a function seems odd to me, I would expect "mr" to be the memory record and not a function. So I'd change that to "getMR" or something like that.
  2. In your if statement you're converting a boolean to a number, I'm thinking you meant to do "tonumber(foo.Value) == hud". Since hud is a number you really want to convert the "foo.Value" to a number.
  3. And also in your if statement you check "IsIncreased" for false. Then you increase "counter" by one, and set "IsIncreased" to true. Thus you only ever increase it once. So you probably want to move the increase for "counter" outside the if statement.
  4. And you're needlessly calling "tonumber" on a number when you increase "counter".

_________________
Back to top
View user's profile Send private message Visit poster's website
icsmoke+
Cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 32

PostPosted: Sat Jan 29, 2022 10:14 am    Post subject: Reply with quote

sorry for bothering you again, can you give an example so i can learn from it, i moved increase for "counter" to anywhere but it wont work i feel like lost in space for it
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Jan 29, 2022 11:15 am    Post subject: This post has 1 review(s) Reply with quote

Code:
if form then form.destroy() form = nil end
form = createForm()
form.Popupmode = 0;
form.Position = poDesktopCenter

if cntimer then cntimer.Destroy() cntimer=nil end
cntimer=createTimer(form) cntimer.Interval=100
cntimer.Enabled=false

local hud = 0
local counter = 0
al = getAddressList()
--mr = al.getMemoryRecordByDescription('infight').Value
mr=0
local nextValue=0

function countme()
 if mr>hud then
  counter=tonumber(counter) + 1
  hud=tonumber(mr)
  else
  counter=tonumber(counter) - 1
  hud=tonumber(mr)
 end
 cntimer.Enabled=false
end

b1=createButton(form)
b1.caption="Back"

b1.OnClick=function()
if mr~=0 then
mr=tonumber(mr) - 1
print("mr: " .. mr .."\ncounter: " .. counter)
cntimer.Enabled=true
else
print("Sorry! mr will not go negative!")
end
end

b2=createButton(form)
b2.caption="Next"
b2.Left=100

b2.OnClick=function()
mr=tonumber(mr) + 1
print("mr: " .. mr .."\ncounter: " .. counter)
cntimer.Enabled=true
end

cntimer.OnTimer=countme


or..
Code:
if cntimer then cntimer.Destroy() cntimer=nil end
cntimer=createTimer()
cntimer.Interval=100
cntimer.Enabled=false

local hud = 1
local counter = 0
al = getAddressList()
mr = al.getMemoryRecordByDescription('infight').Value


function countme()
mr = al.getMemoryRecordByDescription('infight').Value
 if mr>hud then
  counter=tonumber(counter) + 1
  hud=tonumber(mr)
  else
  counter=tonumber(counter) - 1
  hud=tonumber(mr)
 end
 --cntimer.Enabled=false
end


cntimer.OnTimer=countme

UDF1.CEButton1.OnClick=function()
 if cntimer.Enabled==false then
  cntimer.Enabled=true
  print("Timer start!")
  else
  cntimer.Enabled=false
  print("Timer Paused!")
 end
end
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