Structures

Find quick help here to get you started with Hollywood
Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Structures

Hi,

I'm trying to create a initialise Multi-dimensional structure (table ?) with Hollywood.
simple example to be short.

...
...

Can somebody help me ?

Thanks.

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

Re: Structures

Before you can assign stuff to tables, you have to create them first. There are two ways to do that:

Code: Select all

``mytable[1] = "myvalue"``
wont work since there is no mytable existing yet, and hence mytable[1] cannot be accessed.

way 1:

Code: Select all

``````mytable = {}
mytable[1] = "myvalue"``````
FIrst empty mytable was created, then to index spot 1 value "myvalue" was assigned, this works fine.

way 2:

Code: Select all

``mytable = {  [1] =  "myvalue"   }``
This one works as well. Now you are at same time creating the table, as well as telling what should be at index spot 1.

By knowing this you can now get on to multidimensional table:

wrong way:

Code: Select all

``````mytable = {[1] = "myvalue" }
mytable[1][2] = "myvalue"``````
wont work since mytable[1] is value, not a table. To be able to use mytable[1] as a table, and then being able to access mytable[1][2], you first need to make it as a table.

Another wrong way:

Code: Select all

``````mytable[1] = {}
mytable[1][2] = "myvalue"``````
You thought you are making mytable[1] as a table, but it wont work, since you are trying to make a table under a non existing table, you first need to make mytale before you can make mytable[1]

first way:

Code: Select all

``````mytable = {}
mytable[1] = {}
mytable[1][2] = "myvalue"``````
works. Now you first made mytable, and under mytable index spot [1] you made another table. Therefore you were able to put to index spot [2] of this new table a value "myvalue".

second way:

Code: Select all

``mytable = { [1] = { [2] = "myvalue" } }``

Code: Select all

``````mytable = {
[1] = { [2] = "myvalue" }
}``````
These two are identical from hollywoods point of view.
In these two, you are both creating mytable as well as mytable[1] and putting "myvalue" at index spot [2] of mytables subtable[1].

This can naturally continue as far as you want:

Code: Select all

``````mytable = {}
mytable[1] = {}
mytable[1][2] = {}
mytable[1][2][3] = {}``````
works.

Just remember not to skip:

Code: Select all

``````mytable={}
mytable[1]= {}
mytable[1][2][3][4] = {}``````
wont work because tables mytable[1][2] and mytable[1][2][3] dont exist yet.

Notice also, that if you have more index spots with subtables, they all need to be created:

Code: Select all

``````mytable = {}
mytable[1] = {}
mytable[2] = {}
mytable[3] = {}
mytable[2][5] = "myvalue"
mytable[4][1] = "mysecondvalue"``````
"myvalue" is assigned correctly, since mytable[2] exists and it is now assigned to index spot 5 "myvalue" value.
"mysecondvalue" doesnt work, since it is trying to access mytable[4] table, which doesnt exist, as mytables were only made up to 3 index spots.

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

Re: Structures

Code: Select all

``````AddressBook={}

Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Re: Structures

Thanks guy. i will try that.

Juan Carlos
Posts: 673
Joined: Mon Sep 06, 2010 1:02 pm
Contact:

Re: Structures

Hollywood needs a good example with a program to use tables, dates like for example a little and easy diary the code uses to help for our projects for all systems no using MUI libs

Sheeva700
Posts: 27
Joined: Sun Mar 22, 2015 8:24 pm

Re: Structures

Working Perfectly. thanks.

Juan Carlos
Posts: 673
Joined: Mon Sep 06, 2010 1:02 pm
Contact:

Re: Structures

And you get save the dates in a file?