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 


compare with Table values

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Aug 20, 2016 12:07 pm    Post subject: compare with Table values Reply with quote

The script below is some of what I want to do.
How can I find out if the variable "value" is less than the table values "Test_Table"?

Code:

Test_Table = {31, 60, 80 , 10}
Value = 7

print("The value is lower than the values of Test Table? " .. That part I do not know :(   )
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sat Aug 20, 2016 1:57 pm    Post subject: Reply with quote

I can't test it here, but have you tried math.min(unpack(Test_Table))
_________________
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
View user's profile Send private message MSN Messenger
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Aug 20, 2016 3:33 pm    Post subject: Reply with quote

One more question. I did the script below and it returns 10 that is correct, 10 is the 4 item in this table. What returns which is the table item with the lowest value?
Code:

Test_Table = {31, 60, 80, 10}
print("Lower value: " .. math.min(unpack(Test_Table)) .. " It's the ".. Still do not know '-' .. " table item")
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sat Aug 20, 2016 3:40 pm    Post subject: Reply with quote

use a for loop
Code:

minindex=1
for i=2 to #Test_Table do
  if Test_Table[i]<Test_Table[minindex] then
    minindex=i
  end
end

_________________
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
View user's profile Send private message MSN Messenger
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sat Aug 20, 2016 5:09 pm    Post subject: Reply with quote

For my first problem solve with this script.
Code:

Test_Table = {31, 60, 50 , 10}
Value= 7

for a,b in pairs(Test_Table) do
   if Value < math.min(unpack(Test_Table)) then
      result='Yes'
   else
      result='No'
   end
end
print("The value is lower than the values of Test Table? "..result)


And for my second problem it works well.
Code:

Test_Table = {31, 60, 50 , 10}

for a,b in pairs(Test_Table) do
   if math.min(unpack(Test_Table)) == b then
      result=a
   end
end
print("Lower value: " .. math.min(unpack(Test_Table)) .. " It's the ".. result .. " table item")
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