Page 1 of 1

trying to get cells name from table and make that cell be empty table

Posted: Tue Mar 05, 2019 10:35 am
by Bugala
Here is line of code that didnt work:

Code: Select all

InsertItem(  Groups, [gamedata.Uniquename[n]] = { }  )
To make it perhaps more understandable, here is what i tried to do:

Code: Select all

table_names = {"Andreas", "Allanon", "SamuraiCrow"}

table_another = {}

insertitem(table_another, [table_names[0]] = {}
And what I would like this to result is in table_another being:

Code: Select all

table_another = { [Andreas] = {} } )
by otherwords, i could then use: table_another.Andreas, if there would be anything to access, since table_another.Andreas is supposed to be an empty table.

You could say that I am trying to get the name of a cell from another tables list of names, and have that cells item be another empty table.

I suppose this is doable, but how?

Re: trying to get cells name from table and make that cell be empty table

Posted: Wed Mar 06, 2019 1:41 am
by SamuraiCrow
You've got an extra square bracket around your table lookup. Change

Code: Select all

InsertItem(  Groups, [gamedata.Uniquename[n]] = { }  )
to

Code: Select all

InsertItem(  Groups, gamedata.Uniquename[n] = { }  )

Re: trying to get cells name from table and make that cell be empty table

Posted: Wed Mar 06, 2019 8:03 am
by Bugala
Tried that, but gives me error:
"Wrong operator for this type!"

I think that is otherwise right, but just missing something somewhat similar to if there is word WORD, and i want to use it, i need to put it with "WORD".

You could say that if i want to add CELL CONTENT to table, i can do it by using {}, as example:

Code: Select all

insertitem(mytable, {cell content})
But in this case i also want to give the name for that CELL, and that is the problem on how to tell that to Hollywood when insertitem to table, or if it is even possible.

Re: trying to get cells name from table and make that cell be empty table

Posted: Wed Mar 06, 2019 2:37 pm
by jPV
I would do it like this, if I understood what you're after...

Code: Select all

table_names = {"Andreas", "Allanon", "SamuraiCrow"}
table_another = {}
table_another[table_names[0]] = {}
DebugPrint(ListItems(table_another["Andreas"])) ; Works
DebugPrint(ListItems(table_another.Andreas)) ; Fails
If you want to use "table_another.Andreas" then you have to initialize the table with lower case indices:

Code: Select all

table_names = {"andreas", "allanon", "samuraicrow"}
table_another = {}
table_another[table_names[0]] = {}
DebugPrint(ListItems(table_another["andreas"])) ; This must be in lower case too
DebugPrint(ListItems(table_another.Andreas)) ; Here you can now use lower or upper case, doesn't matter

Re: trying to get cells name from table and make that cell be empty table

Posted: Wed Mar 06, 2019 2:48 pm
by Bugala
It feels so stupid when you realise you never thought of the obvious solution. Should have thought of that solution.
Since I dont necessarily need InstertItem command to do it, I can do it exactly as you suggested.
Thank You.