Jump to content
  • 0

I'm having trouble with table!


hoangninyb

Question

My code

local Hack = {}
Name = "A"
X_1 = 111
X_2 = 112
X_3 = 113 
item = "/storage/emulated/0/Download/abc1.lua"
table.insert(Hack, Name) 
table.insert(Hack, X_1)
table.insert(Hack, X_2)
table.insert(Hack, X_3)
gg.saveVariable(Hack, item)

after run, i got;

         local a,b,c,d,e,f,g,h,v,t='address','value','flags','name','freeze','freezeType','freezeFrom','freezeTo',nil
v={{'A';111;112;113;};}
return v[1]
            

but file I want:

local a,b,c,d,e,f,g,h,v,t='address','value','flags','name','freeze','freezeType','freezeFrom','freezeTo',nil
v={{['X_2']=112;['X_3']=113;['X_1']=111;['Name']='A';};{nil;};}
t=v[2]
t[1]=v[1]
return v[2]

I don't know where I went wrong! please help me!

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Don't use "table.insert" when you need to add elements with specific keys, just do it directly instead: 

local Hack = {}
Hack.Name = "A" -- same as Hack["Name"] = "A"
Hack.X_1 = 111
Hack.X_2 = 112
Hack.X_3 = 113 
item = "/storage/emulated/0/Download/abc1.lua"
gg.saveVariable(Hack, item)
Link to comment
Share on other sites

1 hour ago, CmP said:

Don't use "table.insert" when you need to add elements with specific keys, just do it directly instead: 

local Hack = {}
Hack.Name = "A" -- same as Hack["Name"] = "A"
Hack.X_1 = 111
Hack.X_2 = 112
Hack.X_3 = 113 
item = "/storage/emulated/0/Download/abc1.lua"
gg.saveVariable(Hack, item)

but I don't just have "A" I also have "B"

Name = "B"

X_1 = 211

X_2 = 224

X_3 = 236

and "C", "D"....

if using but like you the following values will be replaced, i want to insert!

Link to comment
Share on other sites

Then you need sub-tables, for example: 

local Hack = {}
Hack[1] = {}
Hack[1].Name = "A"
Hack[1].X_1 = 111
Hack[1].X_2 = 112
Hack[1].X_3 = 113
Hack[2] = {Name = "B", X_1 = 114, X_2 = 115, X_3 = 116}
item = "/storage/emulated/0/Download/abc1.lua"
gg.saveVariable(Hack, item)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.