View previous topic :: View next topic |
Author |
Message |
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 9:10 am Post subject: Assigning multiple values to a single variable |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Tue Dec 18, 2018 9:38 am Post subject: |
|
|
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 |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 9:48 am Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Tue Dec 18, 2018 10:16 am Post subject: |
|
|
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 |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 10:24 am Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Tue Dec 18, 2018 11:48 am Post subject: |
|
|
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 |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 6:27 pm Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Tue Dec 18, 2018 10:38 pm Post subject: |
|
|
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 |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Wed Dec 19, 2018 12:47 am Post subject: |
|
|
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 |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4300
|
Posted: Wed Dec 19, 2018 9:40 am Post subject: |
|
|
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 |
|
|
|