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] add array from memrec

 
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 Sep 25, 2021 6:01 am    Post subject: [Ask] add array from memrec Reply with quote

hello there,
i want to ask how to add array from memrec and add some formula on it?

let say my address value is 5 then i want to add formula to array table e.g (5-3,5-2,5-1, 5, 5+1, 5+2, 5+3)
Code:

al = getAddressList
mr = al.getMemoryRecordByDescription

arrRange = { 'mr('myaddress').getValue()-3','mr('myaddress').getValue()-2',
        'mr('myaddress').getValue()-1','mr('myaddress').getValue()',
        'mr('myaddress').getValue()+1','mr('myaddress').getValue()+2'
        'mr('myaddress').getValue()+3','mr('myaddress').getValue()+100'
      'mr('myaddress').getValue()100+1','mr('myaddress').getValue()+100+2' and so on }


how to write that formula properly?

so i can use that array like below
Code:

function range()
   if tonumber(mr('NPCName1').getValue()) ==npcname and
           tonumber(mr('crew1').getValue()) == arrRange then
      myfunction()
   end
end


thanks in advance for help[/code]
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Sat Sep 25, 2021 1:12 pm    Post subject: Reply with quote

Are you trying to return a range of values based on the found memrec's value, or just look for a value within a range?
Try using less/greater than if you can, anyway.

_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
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 Sep 25, 2021 5:08 pm    Post subject: Reply with quote

Yes i am looking for value within range and its a coordinat
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Sat Sep 25, 2021 7:20 pm    Post subject: Reply with quote

Code:

function findMemrecValue(memrec,min,max)
  local al = getAddressList()
  for i=0,al.Count-1 do
    if al[i].Description == memrec then
      if tonumber(al[i].Value) > min and tonumber(al[i].Value) < max then
        print(al[i].Value)
      end
    end
  end
end

findMemrecValue("My Memrec",10,30)


If you want it to scan between multiple ranges (10~30 & 35~40 not 31~34) you can just set additional parameters:

Code:

function findMemrecValue(memrec,ranges)
  local al = getAddressList()
  for i=0,al.Count-1 do
    local t = al[i]
    if t.Description == memrec then
      if #ranges % 2 == 0 then
        for o=1,#ranges do
          if o % 2 == 1 then
            if tonumber(t.Value) ~= nil and tonumber(t.Value) > ranges[o] and tonumber(t.Value) < ranges[o+1] then
              print(t.Value)
            end
          end
        end
      else
        print("Uneven amount of integers to compare.")
      end
    end
  end
end

findMemrecValue("My Memrec",{10,30,50,70,90,110})
--looks for values 10~30, 50~70, 90~110


If you want this run often, use a timer:

Code:

function doIt()
  findMemrecValue("My Memrec",{10,30,50,70,90,110})
end

if checkTimer then
 checkTimer.Enabled = false
 checkTimer.Destroy()
 checkTimer = nil
 checkTimer = createTimer(MainForm, false)
 checkTimer.Interval = 1000
 checkTimer.OnTimer = doIt
 checkTimer.Enabled = true
else
 checkTimer = createTimer(MainForm, false)
 checkTimer.Interval = 1000
 checkTimer.OnTimer = doIt
 checkTimer.Enabled = true
end

_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
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: Sun Sep 26, 2021 12:59 am    Post subject: Reply with quote

Veri nice, thanks man...that answer kills the question
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