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 


Assigning multiple values to a single variable

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Tue Dec 18, 2018 9:10 am    Post subject: Assigning multiple values to a single variable Reply with quote

From what I've been reading up on this it seems it might not be possible but I just wanted to double check and ask here if it was or not. So just to clarify

There is no way or trick to ahchieve the following

Words = 'Hi' , 'Go' , 'Yes' , 'No' , 'Dont' , 'Lets'


if (Address == Words) then
DoStuff
end


Otherwise it's going to be a very very long script if i have to do what I plan to do the alternate way.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Dec 18, 2018 9:38 am    Post subject: Reply with quote

Code:
Address == Words

I don't know what you mean by this. Are you asking if those strings are stored sequentially, or the string stored at an address is any one of those words?

Anyway, use a table.
https://www.lua.org/pil/2.5.html
Code:
Words = {'Hi' , 'Go' , 'Yes' , 'No' , 'Dont' , 'Lets'}

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Tue Dec 18, 2018 9:48 am    Post subject: Reply with quote

I mean I want it to work so that if the String Address's value = any of those words I assigned to "Words" variable then the code runs.


So I don't have to do it like this instead

if (Address == 'Hi') or (Address == 'Go') or (Address == 'No') or (Address == 'Dont') or (Address == 'Lets')

I checked out the link you provided. From what I understand of it. Every variable I create and assign values to are added to the table I created at the beginning of the script ? so I'd do something like this


a = {}
a[1] = 'hi'
a[2] = 'Go'
a[3] = 'No'
a[4] = 'Dont'
a[5] = 'Lets'


if (Address == a) then
DoStuff
end


Is that correct or im a bit off ?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Dec 18, 2018 10:16 am    Post subject: Reply with quote

Code:
local a = {'Hi' , 'Go' , 'Yes' , 'No' , 'Dont' , 'Lets'}

local str = readString(address, 16)

for _,v in ipairs(a) do
  if str == v then
    --DoStuff
  end
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Tue Dec 18, 2018 10:24 am    Post subject: Reply with quote

How would I make this work though Parkour ?

words = {}
s = readString("[[[[Game.exe + 004644F0] + 1C] + 0] + 8] + 0")
for w in string.gmatch(s, "%a+") do
words[#words+1] = w
end





local a = {'Hi' , 'Go' , 'Yes' , 'No' , 'Dont' , 'Lets'}
local b = {'sexy' , 'home' , 'sir' , 'way' , 'leave' , 'Dance'}

local str = words[1]
local str1 = words[2]


for _,v in ipairs(a) do
if str == v then
print ('Boooom')
end
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Dec 18, 2018 11:48 am    Post subject: Reply with quote

That looks like valid Lua code. If it's not working, maybe your pointer path is off.

I might be able to provide more help if you tell me what you're trying to do.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Tue Dec 18, 2018 6:27 pm    Post subject: Reply with quote

Oh yes I didn't exactly specify. Well in a situation where there is two words in a string and I want them both to match. So I've added "local str1 = words[2]"

I know this isn't correct but this is what I'm trying to achieve e.g

for _,v in ipairs(a) and _,w in ipairs(b) do
if str == v and str1 == w then
print ('Boooom')
end
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Dec 18, 2018 10:38 pm    Post subject: Reply with quote

A string is just a sequence of characters. You can have spaces in them too:
Code:
local a = {'Hi sexy' , 'Go home' , 'Yes sir' , 'No way' , 'Dont leave' , 'Lets Dance'}

local str = readString(address, 64):match'%a+ %a+'

for _,v in ipairs(a) do
  if str == v then
    --DoStuff
  end
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
MikeNoey
Advanced Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 64

PostPosted: Wed Dec 19, 2018 12:47 am    Post subject: Reply with quote

My last question on this I'm sure. What if only the 3rd word and the 4th word in a string was relevant to my script but the 1st and 2nd words did not matter. How would I write that ?

-- The question marks represent the irrelevant String words

local a = {'??? ??? Poison shot' , '??? ??? Fire Breath' , '??? ??? Slow spasm' , '??? ??? Darkness blast'}

local b = {'??? ??? Blindside' , '??? ??? Freezing' , '??? ??? Pain' , '??? ??? Encumber' , '??? ??? Toxin' , '??? ??? Disease'}




local str = readString("[[[[Game.exe + 004644F0] + 1C] + 0] + 8] + 0", 64):match'%a+ %a+ %a+ %a+'

local str1 = readString("[[[[Game.exe + 004644F0] + 1C] + 0] + 8] + 0", 64):match'%a+ %a+ %a+'


for _,v in ipairs(a) do
if str == v then
Potion = 1
end
end

for _,w in ipairs(b) do
if str1 == w then
Potion = 2
end
end
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Dec 19, 2018 9:40 am    Post subject: Reply with quote

Code:
local str = 'word1 word2 word3 word4'
print(str:match'%w+ %w+ (%w+ %w+)')  -- prints 'word3 word4'

Look at the Lua reference manual for more information on patterns.
https://www.lua.org/manual/5.3/manual.html#6.4.1

_________________
I don't know where I'm going, but I'll figure it out when I get there.
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