View previous topic :: View next topic |
Author |
Message |
AntonVit Advanced Cheater Reputation: 0
Joined: 25 Jan 2014 Posts: 73
|
Posted: Tue Aug 11, 2015 8:25 am Post subject: Lau Decreaseing value |
|
|
Hi, i try to decrease float value with lia script but cant
I want while key pressed value will decrease
this script i tryed
**********************************************
al = getAddressList()
FORWARDLEFTUP = al.getMemoryRecordByDescription("FORWARDLEFTUP")
function checkKeys(timer)
if (isKeyPressed(VK_NUMPAD1) and isKeyPressed(VK_SUBTRACT)) then
A = FORWARDLEFTUP.Value
B = "0.003"
C = A-B
FORWARDLEFTUP.Value=C
end
end
t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkKeys)
timer_setEnabled(t, true)
*********************************************************
Value alaways decrease to aboute zero but under zero (for example -1 or - 1.1) cant. If i try increase it work fine. In firstly FORWARDLEFTUP.Value has value aboue 0.5.
|
|
Back to top |
|
|
Redouane Master Cheater Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Tue Aug 11, 2015 12:48 pm Post subject: Re: Lua Decreaseing value |
|
|
I think this is a bug,because it works just fine with variables declared with Lua,here is a way to reproduce it:
FORWARDLEFTUP is a memory record.
Code: |
x = FORWARDLEFTUP.Value; -- equals (-0.001)
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
return x == FORWARDLEFTUP.Value |
@DarkByte
the code prints false to the console !
A few tips to improve your code:
Code: |
FORWARDLEFTUP = getAddressList().getMemoryRecordByDescription("FORWARDLEFTUP")
local hotkey = createHotkey(function ()
-- No need for A,B and C
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003;
end,VK_1,VK_SUBTRACT);
|
|
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Tue Aug 11, 2015 5:33 pm Post subject: |
|
|
Sounds like a rounding issue when converting between floats and strings. Use:
Code: | writeFloat(FORWARDLEFTUP.CurrentAddress, readFloat(FORWARDLEFTUP.CurrentAddress) - 0.003) |
|
|
Back to top |
|
|
AntonVit Advanced Cheater Reputation: 0
Joined: 25 Jan 2014 Posts: 73
|
Posted: Wed Aug 12, 2015 3:00 am Post subject: |
|
|
Thanks
Tryed
*******************************************
Code: | al = getAddressList()
FORWARDLEFTUP = al.getMemoryRecordByDescription("FORWARDLEFTUP")
function checkKeys(timer)
if (isKeyPressed(VK_NUMPAD1) and isKeyPressed(VK_SUBTRACT)) then
x = FORWARDLEFTUP.Value; -- equals (-0.001)
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
FORWARDLEFTUP.Value = FORWARDLEFTUP.Value - 0.003
x = x - 0.003;
return x == FORWARDLEFTUP.Value
end
end
t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkKeys)
timer_setEnabled(t, true) |
but value decrease again to aboute zero and not under
and tryed
Code: | al = getAddressList()
FORWARDLEFTUP = al.getMemoryRecordByDescription("FORWARDLEFTUP")
function checkKeys(timer)
if (isKeyPressed(VK_NUMPAD1) and isKeyPressed(VK_SUBTRACT)) then
writeFloat("53F6BF44", readFloat("53F6BF44") - 0.003)
end
end
t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkKeys)
timer_setEnabled(t, true) |
work fine
Thanks You all for help. Now it work
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Wed Aug 12, 2015 3:20 am Post subject: |
|
|
It's fixed in the next lua version that comes with ce
also, this script is the same:
Code: |
v="-0.001"
x=v
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
print(x)
print(v)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
AntonVit Advanced Cheater Reputation: 0
Joined: 25 Jan 2014 Posts: 73
|
Posted: Thu Aug 20, 2015 4:25 am Post subject: |
|
|
Dark Byte wrote: | It's fixed in the next lua version that comes with ce
also, this script is the same:
Code: |
v="-0.001"
x=v
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
v=tostring(v-0.003)
x=x-0.003
print(x)
print(v)
|
|
In main page of site link (button) for new version of CE (there is 6.4) Or i need wait some for new CE (6.5) in which new fixed lua?
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Thu Aug 20, 2015 4:35 am Post subject: |
|
|
Yes, wait for 6.5
For now just work around it
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
mgr.inz.Player I post too much Reputation: 218
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
Posted: Fri Aug 21, 2015 1:22 pm Post subject: |
|
|
In Lua5.1 and before, tonumber function and automatic string conversion (from string to number) has a bug.
It doesn't like "0" (zero) between "-" (minus) and "." (decimal separator).
This bug was reported here:
http://cheatengine.org/mantis/view.php?id=328
We can fix tonumber function with this:
Code: | if original_tonumber==nil then
original_tonumber=tonumber
end
function tonumber(value)
value = value:gsub( "%-0+%." , "-." ):gsub("%-%-","")
return original_tonumber(value)
end
|
first gsub replaces all "-0." with "-." (also any amount of zeros between minus and decimal separator)
second gsub replaces all "--" into empty string
From now on, it will recognize "-0.234" and "-000.234" and "---0.234" and ..... (you get the idea)
as number -0.234
Now just use corrected tonumber function (automatic conversion is still broken):
Code: | v="-0.001"
v=tostring(tonumber(v)-0.003)
v=tostring(tonumber(v)-0.003)
v=tostring(tonumber(v)-0.003)
v=tostring(tonumber(v)-0.003)
|
So, for you it will be:
Code: | FORWARDLEFTUP.Value = tostring(tonumber(FORWARDLEFTUP.Value) - 0.003) |
_________________
|
|
Back to top |
|
|
|