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] help to understanding iterator

 
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: 29

PostPosted: Wed Mar 02, 2022 2:58 am    Post subject: [ask] help to understanding iterator Reply with quote

hello there master, please help me to understanding about iterator, i have code below that makes me confused. here's the code

Code:

number = 50
a1 = 1
a2 = 50
a3 = 2
a4 = 50
number1 = 100
aa1 = 1
aa2 = 100
aa3 = 300
aa4 = 100

function k1() a = a1 + aa1 end
function k2() a = a2 + aa2 end
function k3() a = a3 + aa4 end
function k4() a = a4 + aa4 end

donestate = false
function z()
for i = 1, 4 do
if donestate == false then
if 'a'..i == number and -- check if the value is true or false from a1 - a4
   'aa'..i == number1 then -- check if the value is true or false from aa1 - aa4
   print('right')
   print('a'..i)
   print('aa'..i)
   ('k'..i)() -- doing something when check is true from function k1 - k4()
   donestate = true
   else
       print('wrong')
       donestate = false
       end
end
end
end


thanks in advance
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

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

PostPosted: Wed Mar 02, 2022 4:58 am    Post subject: Reply with quote

An iterator is used in loops for example:
Code:

for i = 0, 10 do
  print('The loop is currently at ' .. tostring(i))
end


In this code, i would be the iterator.

As for your code, the condition will never succeed because 'a' is treated as a string, it will never be a number. What is it you're trying to achieve?
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1531

PostPosted: Wed Mar 02, 2022 5:45 am    Post subject: Reply with quote

Interpret variables in a global table.
In this way, it is possible to reach them from a wider angle.

Code:
local scope={}

number = 50
scope.a1 = 1
scope.a2 = 50
scope.a3 = 2
scope.a4 = 50
number1 = 100
scope.aa1 = 1
scope.aa2 = 100
scope.aa3 = 300
scope.aa4 = 100

function scope.k1() a = scope.a1 + scope.aa1 return tonumber(a) end
function scope.k2() a = scope.a2 + scope.aa2 return tonumber(a) end
function scope.k3() a = scope.a3 + scope.aa4 return tonumber(a) end
function scope.k4() a = scope.a4 + scope.aa4 return tonumber(a) end

donestate = false
function z()
for i = 1, 4 do
if donestate == false then
if scope['a'..i] == number and -- check if the value is true or false from a1 - a4
   scope['aa'..i] == number1 then -- check if the value is true or false from aa1 - aa4
   print('right: ' .. 'a' .. i .. ' - aa' .. i)
   aFind1=tonumber(scope['a'..i])
   aFind2=tonumber(scope['aa'..i])
   print(aFind1)
   print(aFind2)
   aFind3=(scope['k'..i])() -- doing something when check is true from function k1 - k4()
   print("Find: " .. aFind3)
   donestate = true
   else
       print('wrong: ' .. 'a' .. i .. ' - aa' .. i)
       donestate = false
       end
end
end
end

z()

_________________
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
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