|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 68
|
Posted: Sun Jul 17, 2022 10:49 am Post subject: 2 data variable |
|
|
sorry for my bad english,
i have mini database like this
Code: | id name weapon
01 Crono Katanas
02 Marle Bows
03 Lucca Guns
04 Robo Mechanical Arms
05 Frog Swords
06 Ayla Fists
07 Magus Scythes
|
and this is sample of my code
Code: | HeroID = {}
HeroID[1] = "Crono"
--do same until Magus
HeroWeapon = {}
HeroWeapon[1] = "Katanas"
--do same until Scythes
|
is there any syntax that make that both variable into 1 line?
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Sun Jul 17, 2022 12:25 pm Post subject: |
|
|
Simple:
Code: | HeroID = {}
HeroID[1] = "Crono"
HeroWeapon = {}
HeroWeapon[1] = "Katanas"
res = HeroID[1].." = "..HeroWeapon[1]
print(res) |
Single table:
Code: | HeroAll = {Crono="Katanas",
Marle="Bows",
Lucca="Guns",
Robo="Mechanical Arms",
Frog="Swords",
Ayla="Fists",
Magus="Scythes"}
for i,k in pairs(HeroAll) do
print(i.." - "..k)
end
id = "Lucca"
print("\nLucca: "..HeroAll[id])
print("Marle: "..HeroAll.Marle) |
Comprehensive:
Code: | Hero = [[Crono
Marle
Lucca
Robo
Frog
Ayla
Magus]]
Weapon = [[Katanas
Bows
Guns
Mechanical Arms
Swords
Fists
Scythes]]
HeroID = {}
HeroWeapon = {}
HeroIDWeapon = {}
sl1 = createStringList()
sl1.Text = Hero
sl2 = createStringList()
sl2.Text = Weapon
for i=0, sl1.Count -1 do
HeroID[i+1] = sl1[i]
HeroWeapon[i+1] = sl2[i]
end
sl1.Destroy()
sl2.Destroy()
for i=1, #HeroID do
HeroIDWeapon[i] = HeroID[i]
HeroIDWeapon[HeroID[i]] = HeroWeapon[i]
end
for i,k in pairs(HeroIDWeapon) do
print(i,k)
end |
Take what you need from the examples.
_________________
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
Posted: Sun Jul 17, 2022 1:41 pm Post subject: |
|
|
Do you mean combining the HeroID and HeroWeapon tables? Make it a table of tables:
Code: | Heros = {
{
id = '01',
name = 'Crono',
weapon = 'Katanas',
},
{
id = '02',
name = 'Marle',
weapon = 'Bows',
},
-- ...
}
for i,v in ipairs(Heros) do
print(('%d: id = %s, name = %s, weapon = %s'):format(i, v.id, v.name, v.weapon))
end |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
kucingkembar Advanced Cheater Reputation: 0
Joined: 08 Oct 2020 Posts: 68
|
Posted: Sun Jul 17, 2022 11:07 pm Post subject: |
|
|
thank you AylinCE, But ParkourPenguin method is what I looking for,
thank you ParkourPenguin, your answer is works
EDIT:
how to: i like to print only "weapon" with id of "05"?
Nevermind, it like this "print(Heros[1].name)"
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Tue Jul 19, 2022 2:28 am Post subject: |
|
|
Code: | Heros = {
{
id = '01',
name = 'Crono',
weapon = 'Katanas',
},
{
id = '02',
name = 'Marle',
weapon = 'Bows',
},
-- ...
}
function searchTbl(a,fnd)
res = "not found!"
for i,v in ipairs(Heros) do
if v.id==a then
if fnd==1 then
res = v.name
elseif fnd==2 then
res = v.weapon
else
res = ('%d: id = %s, name = %s, weapon = %s'):format(i, v.id, v.name, v.weapon)
end
end
return res
end
aa1 = searchTbl("05",1)
aa2 = searchTbl("05",2)
aa3 = searchTbl("04",3)
print (aa1)
print (aa2)
print (aa3)
|
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Tue Jul 19, 2022 8:17 pm Post subject: |
|
|
AylinCE wrote: | Code: | Heros = {
{
id = '01',
name = 'Crono',
weapon = 'Katanas',
},
{
id = '02',
name = 'Marle',
weapon = 'Bows',
},
-- ...
}
function searchTbl(a,fnd)
res = "not found!"
for i,v in ipairs(Heros) do
if v.id==a then
if fnd==1 then
res = v.name
elseif fnd==2 then
res = v.weapon
else
res = ('%d: id = %s, name = %s, weapon = %s'):format(i, v.id, v.name, v.weapon)
end
end
return res
end
aa1 = searchTbl("05",1)
aa2 = searchTbl("05",2)
aa3 = searchTbl("04",3)
print (aa1)
print (aa2)
print (aa3)
|
|
1. Need one more "end" statement to close the function
2. Avoid the function to show "not found", if find data on the table has success and finding process has reach the and of the table
3. Note, Lua table index start from 1
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 31
Joined: 16 Feb 2017 Posts: 1234
|
Posted: Wed Jul 20, 2022 12:13 am Post subject: |
|
|
I wrote the code on the phone in answer mode, I didn't get a chance to try it.
An "end" factor and cascading inserts were made.
In my case the latest version is working.
Code: |
Heros = {
{
id = '01',
name = 'Crono',
weapon = 'Katanas',
},
{
id = '02',
name = 'Marle',
weapon = 'Bows',
},
-- ...
}
function searchTbl(a,fnd)
res = ""
for i,v in ipairs(Heros) do
if a==v.id then
if fnd==1 then
res = v.name
elseif fnd==2 then
res = v.weapon
elseif fnd==3 then
res = v.name.." "..v.weapon
else
res = ('%s %s %s'):format(v.id, v.name, v.weapon)
end
end
end
return res
end
aa1 = searchTbl("01",1)
aa2 = searchTbl("01",2)
aa3 = searchTbl("02",3)
aa0 = searchTbl("01",0)
print (aa1)
print (aa2)
print (aa3)
print (aa0)
|
result:
Crono
Katanas
Marle Bows
01 Crono Katanas
_________________
|
|
Back to top |
|
|
|
|
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
|
|