Gothic Online Forums
Script doesn't work - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Scripting Help (https://archive.gothic-online.com/forum-12.html)
+--- Thread: Script doesn't work (/thread-259.html)



Script doesn't work - Tuv - 28.12.2015

Hello, please help me understand what did I do wrong with this code, I don't know why draw and messages "VISMENU HIDDEN" and "VISMENU SHOWN" don't appear.
http://pastebin.com/4pFUYCH1
I'm not very familiar with classess but this is basically a copy-paste of script "statistics.nut".


RE: Script doesn't work - Buras - 28.12.2015

I think I made this work. Try that:
Link


RE: Script doesn't work - Tuv - 28.12.2015

Thank you! I've tried everything but I've missed it
title_DrawVisual = null;


RE: Script doesn't work - Bimbol - 28.12.2015

If you using class you have to remember, that any class vars, must be initialized in class constructor, and before initializing they have to be declared.

So for example:
Squirrel Script
  1. class Foo
  2. {
  3. constructor()
  4. {
  5. var1 = "Var 1";
  6. var2 = 921323;
  7. }
  8.  
  9. var1 = null;
  10. var2 = null;
  11. var3 = null; // This one isn't initialized so will be static member of this class
  12. };





RE: Script doesn't work - Tuv - 28.12.2015

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'


RE: Script doesn't work - Bimbol - 28.12.2015

(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. };