View previous topic :: View next topic |
Author |
Message |
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Thu Jan 27, 2022 10:31 am Post subject: [ask] counter wont increased [solved] |
|
|
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 |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Thu Jan 27, 2022 11:56 am Post subject: |
|
|
- 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.
- 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.
- 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.
- And you're needlessly calling "tonumber" on a number when you increase "counter".
_________________
|
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Sat Jan 29, 2022 10:14 am Post subject: |
|
|
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 |
|
|
ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sat Jan 29, 2022 11:15 am Post subject: |
|
|
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 |
|
|
|