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 


Odd way to display numbers
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Wed Feb 02, 2022 6:45 pm    Post subject: Odd way to display numbers Reply with quote

suppose I have a number say 1234567890 The game I have breaks these numbers into
Address 1 would contain values 1-99, in this case 90
Address 2 would contain values 100-9999 in this case 78
Address 3 would contain values 10000-999999 in this case 56
Address 4 would contain numbers 1 *1^6-99999999 in this case 34
Address 5 would contain values 1 *10*-9999999999 in this case 12.
The values in each address all have the range of 1-99.
I've been going over various formulas and running into numbers that are not correct. Any coding ideas?
Back to top
View user's profile Send private message Yahoo Messenger
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Thu Feb 03, 2022 5:57 am    Post subject: Reply with quote

I don't want you to think you are being ignored, but I feel your initial post lacks information; it's just too vague. I would advise providing actual data rather than a hypothetical scenario.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 6:31 am    Post subject: Reply with quote

I never believe I was ignored, but I'm searching for coding scheme that will take a number and chop it into 10^2 10^4 etc. and display those two digits that represent those value.

345 would be 0 0 0 3 45
5684 would be 0 0 0 56 84
672301 would be 0 0 67 23 01
Is that clearer?
Back to top
View user's profile Send private message Yahoo Messenger
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Thu Feb 03, 2022 7:16 am    Post subject: Reply with quote

I know that you can get something very close in Excel with a formula, I am just not sure how you would account for the extra zeros. Probably easy for Excel experts.
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Thu Feb 03, 2022 8:00 am    Post subject: Reply with quote

You can 'split' a number using divide and modulus operation like,
math.floor(12345 / 100 ) -> 123
12345 % 100 -> 45
Here a sample iterator (use in 'for ... in .. do' ) to generate such numbers,
Code:

function repeatDivMod(M, D)
  local n, d, r = M, D or 100
  return function()
    if n>0 and d>0 then
      n, r = math.floor(n/d), n % d
      return n, r
    end
  end
end
-- test
local todisplay = {}
for n,r in repeatDivMod(71234567890,100)do
  todisplay[1+#todisplay] = r
end
print(table.concat(todisplay,', '))
-- output
90, 78, 56, 34, 12, 7

Not work for negative numbers.

_________________
- Retarded.
Back to top
View user's profile Send private message
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 9:07 am    Post subject: Reply with quote

++METHOS wrote:
I know that you can get something very close in Excel with a formula, I am just not sure how you would account for the extra zeros. Probably easy for Excel experts.


That's the problem because the number we are dealing with has a large range 0-9999999999

Any formula needs to be able to deal with all those possibilities.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1526

PostPosted: Thu Feb 03, 2022 9:13 am    Post subject: Reply with quote

bknight2602 wrote:
I never believe I was ignored, but I'm searching for coding scheme that will take a number and chop it into 10^2 10^4 etc. and display those two digits that represent those value.

345 would be 0 0 0 3 45
5684 would be 0 0 0 56 84
672301 would be 0 0 67 23 01
Is that clearer?


I will not do complex calculations.
I will only take it superficially and give an example:

Code:
function convert1(num)
b = (tostring(num)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end

--Format by splitting:

function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))
print("num1:" .. num1)
b = (tostring(num1)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end

print("convert1.3: " .. convert1(345))
print("convert1.7: " .. convert1(6723012)) --opps! max=9
print("convert2/2: " .. convert2(123456789,2))
print("convert2/4: " .. convert2(123456789,4))

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 9:30 am    Post subject: Reply with quote

panraven wrote:
You can 'split' a number using divide and modulus operation like,
math.floor(12345 / 100 ) -> 123
12345 % 100 -> 45
Here a sample iterator (use in 'for ... in .. do' ) to generate such numbers,
Code:

function repeatDivMod(M, D)
  local n, d, r = M, D or 100
  return function()
    if n>0 and d>0 then
      n, r = math.floor(n/d), n % d
      return n, r
    end
  end
end
-- test
local todisplay = {}
for n,r in repeatDivMod(71234567890,100)do
  todisplay[1+#todisplay] = r
end
print(table.concat(todisplay,', '))
-- output
90, 78, 56, 34, 12, 7

Not work for negative numbers.

That works great but I don't understand the scheme, so I'll ask for some expansion of the idea (which is great)
I need to be able to take these outputs and set them into specific addresses in my table. Now for my questions.
So n would be described as n1, n2 , n3 etc.?
It looks like the last n will always be tens digits so n-1 would be thousands etc., correct?
All of the larger address values would be zero in a number like 5799. There would be only two significant entries the rest would be 0, i.e. 99 57 0 0 0. How to set those specific addresses to 0?
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1526

PostPosted: Thu Feb 03, 2022 10:58 am    Post subject: Reply with quote

bknight2602 wrote:
I can't double post yet but this is my question in a quote.
AylinCE wrote:
..


Another great example that I don't understand the scheme nor how to arrive at each element used in setting values in specific addresses.
Your convert2/2 and 2/4 but we don't know the number in advance which scheme would work for an unknown variable 0-9999999999 and then how would I obtain each output to assign values in specific address?


I still don't understand the logic of splitting a plain value into Aobs-style bytes.
I think that's why I posted a plain replacement code.

As far as I understand from the question, you can turn to any of the following stages (ideas):


Code:
function searchAddrValue(search)
rst=""
local aobs1=AOBScan(search)

if aobs1~=nil then

aobs2=readInteger(aobs1)
if (string.len(aobs2))==3 then
rst=rst .. convert2(aobs2,1)
end

if (string.len(aobs2))==4 then
rst=rst .. convert2(aobs2,2)
end

if (string.len(aobs2))==5 then
rst=rst .. convert2(aobs2,3)
end

if (string.len(aobs2))==6 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==7 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==8 then
rst=rst .. convert2(aobs2,5)
end

if (string.len(aobs2))==9 then
rst=rst .. convert2(aobs2,5)
end
end
return rst
end

src=searchAddrValue(tostring("00 00 80 3F 00 ?? ?? ?? FF"))

print(src)


Now you can expand the question a little more to understand better. Wink

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 11:20 am    Post subject: Reply with quote

AylinCE wrote:
bknight2602 wrote:
I never believe I was ignored, but I'm searching for coding scheme that will take a number and chop it into 10^2 10^4 etc. and display those two digits that represent those value.

345 would be 0 0 0 3 45
5684 would be 0 0 0 56 84
672301 would be 0 0 67 23 01
Is that clearer?


I will not do complex calculations.
I will only take it superficially and give an example:

Code:
function convert1(num)
b = (tostring(num)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end

--Format by splitting:

function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))
print("num1:" .. num1)
b = (tostring(num1)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end

print("convert1.3: " .. convert1(345))
print("convert1.7: " .. convert1(6723012)) --opps! max=9
print("convert2/2: " .. convert2(123456789,2))
print("convert2/4: " .. convert2(123456789,4))


By inspection one knows that 345 has length of three and this example should output 0 0 0 3 45
again, your second example 6723012, has a length of 7 and it output should be 0 6 72 30 12
Your third example 123456789 has a length of 9 and its output should be 1 23 45 67 89.
The problem is we don't know the length of the number, so we need a routine that will handle any/all of these variables.
This attempt seems to me to work better than your second. Now you asked why to break any number in this range? I need them to put those parts into specific addresses in my table.

ETA: It seems like one could use a len command to use in your example to solve one question.
Back to top
View user's profile Send private message Yahoo Messenger
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1526

PostPosted: Thu Feb 03, 2022 11:55 am    Post subject: Reply with quote

Here is an example that you can edit and expand:

Code:
function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))
print("num1:" .. num1)
b = (tostring(num1)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end


function searchAddrValue(search)
rst=""
--local aobs1=AOBScan(search)
local aobs2=search
if aobs2~=nil then

--aobs2=readInteger(aobs1)
if (string.len(aobs2))==3 then
rst=rst .. convert2(aobs2,1)
end

if (string.len(aobs2))==4 then
rst=rst .. convert2(aobs2,2)
end

if (string.len(aobs2))==5 then
rst=rst .. convert2(aobs2,3)
end

if (string.len(aobs2))==6 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==7 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==8 then
rst=rst .. convert2(aobs2,5)
end

if (string.len(aobs2))==9 then
rst=rst .. convert2(aobs2,5)
end

if (string.len(aobs2))==10 then
rst=rst .. convert2(aobs2,5)
end
end
print(rst)
return rst
end

--src=searchAddrValue(tostring(123))
--src=searchAddrValue(tostring(1234))
--src=searchAddrValue(tostring(12345))
src=searchAddrValue(tostring(9999999999)) --len-10


If you don't want to split, type 1 in the code equivalent:
Code:
if (string.len(aobs2))==9 then
rst=rst .. convert2(aobs2,1)
end

Otherwise, you can specify how much you want to shrink in the template:

Code:
if (string.len(aobs2))==10 then
rst=rst .. convert2(aobs2,2)
end


If you don't want to split, type 1 in the code equivalent:

Otherwise, you can specify how much you want to shrink in the template:

You can export these results to certain address values (in your Table):

No; I don't know where you got these address values from.
A specific address scan (in Lua Script and a code that finds multiple values)
Found list? (Within too many addresses and values)
Address list (Too many addresses and values)

Just find a specific address, convert it to value with "readInteger("address")" and format the value with "src=searchAddrValue(tostring(9999999999))" and leave it as "oldvalue=src" where you want to write the value in your table.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 12:49 pm    Post subject: Reply with quote

AylinCE wrote:
Here is an example that you can edit and expand:

Code:
function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))
print("num1:" .. num1)
b = (tostring(num1)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end


function searchAddrValue(search)
rst=""
--local aobs1=AOBScan(search)
local aobs2=search
if aobs2~=nil then

--aobs2=readInteger(aobs1)
if (string.len(aobs2))==3 then
rst=rst .. convert2(aobs2,1)
end

if (string.len(aobs2))==4 then
rst=rst .. convert2(aobs2,2)
end

if (string.len(aobs2))==5 then
rst=rst .. convert2(aobs2,3)
end

if (string.len(aobs2))==6 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==7 then
rst=rst .. convert2(aobs2,4)
end

if (string.len(aobs2))==8 then
rst=rst .. convert2(aobs2,5)
end

if (string.len(aobs2))==9 then
rst=rst .. convert2(aobs2,5)
end

if (string.len(aobs2))==10 then
rst=rst .. convert2(aobs2,5)
end
end
print(rst)
return rst
end

--src=searchAddrValue(tostring(123))
--src=searchAddrValue(tostring(1234))
--src=searchAddrValue(tostring(12345))
src=searchAddrValue(tostring(9999999999)) --len-10


If you don't want to split, type 1 in the code equivalent:
Code:
if (string.len(aobs2))==9 then
rst=rst .. convert2(aobs2,1)
end

Otherwise, you can specify how much you want to shrink in the template:

Code:
if (string.len(aobs2))==10 then
rst=rst .. convert2(aobs2,2)
end


If you don't want to split, type 1 in the code equivalent:

Otherwise, you can specify how much you want to shrink in the template:

You can export these results to certain address values (in your Table):

No; I don't know where you got these address values from.
A specific address scan (in Lua Script and a code that finds multiple values)
Found list? (Within too many addresses and values)
Address list (Too many addresses and values)

Just find a specific address, convert it to value with "readInteger("address")" and format the value with "src=searchAddrValue(tostring(9999999999))" and leave it as "oldvalue=src" where you want to write the value in your table.

The values are located in a listview, and I select one of them. This represents the variable. Now the outputs will represent the values of fixed address 1, fixed address 2, fixed address 3, fixed address 4 and fixed address 5. The code should be able to insert those values into the five addresses.
Back to top
View user's profile Send private message Yahoo Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Thu Feb 03, 2022 2:52 pm    Post subject: Reply with quote

It can be match values with your addresses (or memory record identify by description etc) like this:
Code:

local addies = {'1ab000','1ab004','1ab008','1ab00c','1ab010'}
local nextmod = repeatDivMod(71234567890,100)
for i=1,#addies do
  local _, r = nextmod() -- nextmod  return 2 values, we only interested in second one
  print(addies[i],r or 0) -- 'or 0' to set default value
end

_________________
- Retarded.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1526

PostPosted: Thu Feb 03, 2022 3:57 pm    Post subject: Reply with quote

We are still far from a scenario, we proceed with assumptions.

Code:
--We are still stuck on this code.
--Let's rearrange it and set it for 5 outputs:

function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))
--print("num1:" .. num1)
b = (tostring(num1)):reverse()
lnn="0 "
a = b:gsub("..", "%1 "):sub(1,-1)
--print("a:"..a)
a=(a):reverse():sub(1,-1)
if (a):sub(1,1)==" " then a=(a):sub(2, -1) end
--print("a1:"..a)
a1=string.len(a) / 3
a1=math.floor(5 - tonumber(a1))
--print(a1)
ln=string.rep(lnn, a1) .. a
--print(ln)
return ln
end


--Let's take an address value from the list:

adrr="06D9EC68" --The address is an example!
addrValue=readInteger(adrr) --Get the current value of your address.
--print(addrValue) -- 121863880 (example!)

--Now let's divide them into 5 different formats
--or assign them to 5 addresses:

adrrValrst1=convert2(addrValue,1)
adrrValrst2=convert2(addrValue,2)
adrrValrst3=convert2(addrValue,4)
adrrValrst4=convert2(addrValue,5)
adrrValrst5=convert2(addrValue,7)

--And you choose which 5 address values to write them to;

-- address1.value=adrrValrst1
-- etc ..
-- etc ..


If you can achieve the results you want with the existing code, you can distribute those results to other addresses.
But I didn't understand how to write this result (output) "1 21 86 38 80" to an address.
I think you'll make it.


EDIT:

bknight2602 wrote:
The first two lines of your most recent post
num=5799--from the list view
function convert2(num,fmt)
num1=math.floor(tonumber(num) / tonumber(fmt))

What is fmt?
The code gives Error:[string "num=5799
..."]:3: attempt to perform arithmetic on a nil value
Script Error I put 100 into where fmt was and obtained similar errors.


addrValue=Address.value
fmt=1 ("fmt" or the division operation that reduces the format value. If you don't want to divide the value (2,3,4, etc.), put 1 there.)
convert2(addrValue,1)

Code:
hnmel1 = addresslist_getMemoryRecordByDescription(addresslist, "exaple1")

result1=convert2(hnmel1.value,1)  -- value / 1 = convert(value) .. value / 2 = convert(new value)..

Where are you going to write the new formatted value?

hnmel1.value=result1 --?

hnmel2 = addresslist_getMemoryRecordByDescription(addresslist, "exaple2")

hnmel2.value=result1

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 586

PostPosted: Thu Feb 03, 2022 8:23 pm    Post subject: Reply with quote

AylinCE wrote:

after inserting a fixed num = 5799 in the function
and printing
print(adrrValrst1)
print(adrrValrst2)
print(adrrValrst3)
after the
adrrValrst1=convert2(addrValue,1)
adrrValrst2=convert2(addrValue,2)
adrrValrst3=convert2(addrValue,4)
The results of those 3 outputs
are:
0 0 0 57 99
0 0 0 57 99
0 0 0 57 99
This is probably what you were indicating in a previous post.
How the output to the function, which by the way is correct into five discrete
addresses the 99 goes into one, the 57 goes into another and 0 go into 3 more addresses.
we need to break apart the aa bb cc dd ee into five answers.
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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