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

Discuss any general programming issues here
Post Reply
Bugala
Posts: 745
Joined: Sun Feb 14, 2010 7:11 pm

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

Post by Bugala » Tue Mar 05, 2019 10:35 am

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?

SamuraiCrow
Posts: 210
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

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

Post by SamuraiCrow » Wed Mar 06, 2019 1:41 am

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] = { }  )

Bugala
Posts: 745
Joined: Sun Feb 14, 2010 7:11 pm

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

Post by Bugala » Wed Mar 06, 2019 8:03 am

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.

User avatar
jPV
Posts: 238
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

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

Post by jPV » Wed Mar 06, 2019 2:37 pm

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

Bugala
Posts: 745
Joined: Sun Feb 14, 2010 7:11 pm

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

Post by Bugala » Wed Mar 06, 2019 2:48 pm

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.

Post Reply