Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script doesn't work
#6
(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
  1. class Foo
  2. {
  3. constructor()
  4. {
  5. _table = [];
  6. _table.append("Hello");
  7. _table.append("XASDASDADSa");
  8. _table.append(22);
  9. // Or
  10. /*
  11.   _table = array(3); // Array size 3
  12.   _table[1] = "Hello";
  13.   _table[2] = "XASDASDADSa";
  14.   _table[3] = 22;
  15.   */
  16. }
  17.  
  18. _table = null;
  19. };



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
  1. class Foo
  2. {
  3. constructor()
  4. {
  5. _table = {};
  6. // Only way is create slot, and now will work
  7. _table[1] <- "Hello";
  8. _table[2] <- "XASDASDADSa";
  9. _table[3] <- 22;
  10.  
  11. // Slot can be deleted with keyworld delete slot;
  12. }
  13.  
  14. _table = null;
  15. };


Reply


Messages In This Thread
Script doesn't work - by Tuv - 28.12.2015, 11:36
RE: Script doesn't work - by Buras - 28.12.2015, 11:49
RE: Script doesn't work - by Tuv - 28.12.2015, 12:42
RE: Script doesn't work - by Bimbol - 28.12.2015, 13:17
RE: Script doesn't work - by Tuv - 28.12.2015, 17:25
RE: Script doesn't work - by Bimbol - 28.12.2015, 17:34

Possibly Related Threads…
Thread Author Replies Views Last Post
  Script Ayate 3 2,962 27.12.2015, 14:12
Last Post: Buras

Forum Jump:


Users browsing this thread: 1 Guest(s)