(28.12.2015, 17:25)Tuv Wrote: Yes, I know that already, and actually I wonder why i can't make class like this
Code:class Foo
{
constructor()
{
table = {};
table[1] = "Hello";
table[2] = "XASDASDADSa";
table[3] = 22;
}
for(local i = 1; i < 3; i++)
table[i] = null;
};
compiler says: expected 'IDENTIFIER'
Becasue doing this u spoil sytax of the class. Compiles says, that he wait for some identifier, which wasn't founded. In ur case u used reserved name table.
The correct way is:
Squirrel Script
- class Foo
- {
- constructor()
- {
- _table = [];
- _table.append("Hello");
- _table.append("XASDASDADSa");
- _table.append(22);
- // Or
- /*
- _table = array(3); // Array size 3
- _table[1] = "Hello";
- _table[2] = "XASDASDADSa";
- _table[3] = 22;
- */
- }
-
- _table = null;
- };
In squirrel we have array, and tables. They are different containers of data.
EDIT. If you really want to use tables then here is an example:
Squirrel Script
- class Foo
- {
- constructor()
- {
- _table = {};
- // Only way is create slot, and now will work
- _table[1] <- "Hello";
- _table[2] <- "XASDASDADSa";
- _table[3] <- 22;
-
- // Slot can be deleted with keyworld delete slot;
- }
-
- _table = null;
- };