Jump to content

Table


FatalTerror

Recommended Posts

Hi there,

I wanted to know, how to access to a table value when I'm already on that table.

Like this:

  
myTable = { 
a = {test = "ok"}, 
b = {test = myTable.a.test} 
} 
  

As you can see, the myTable.b is trying to access to myTable.a but he can't access to this because it's on the same var.

How can I do that? If it's possible?

Thanks for any help.

Regards, FatalTerror.

Link to comment
  • Moderators
myTable = { 
    a = {test = "ok"} 
} 
myTable.b = {} 
myTable.b.test = myTable.a.test 
  
outputChatBox(tostring(myTable.a.test)) 
outputChatBox(tostring(myTable.b.test)) 

no it isn't, cause you can't index something that hasn't been created yet.

  
myTable = { 
  
  
-- not yet created 
  
  
} -- created 

Link to comment

It doesn't work because the table isn't loaded yet.

Tested it serveral times and this will output "okay" after that i realised that the table isn't loaded yet

  
derptest = "okey" 
  
myTable = { 
a = {test = "okTESTA"}, 
b = {test = derptest} 
} 
  
addCommandHandler ( "derp", function () 
outputChatBox ( myTable.b.test ) 
end) 

edit: as IIYAMA says (really can't typ that name).

Link to comment

Yes but personaly, I really don't want to write an entire file with this method.

Sure that my way isn't possible?

Well loop's are a solution. If not a txt generator made in (c/c++) is an another option (if you don't wanna use the loop's on every resource start.)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...