Skip to content

Nested structures

fot1fot1 Member Posts: 74
edited December 2018 in Builders - Scripting
The following code gives an access violation when trying to compile:
struct Bar {
    string baz;
};

struct Foo {
   struct Bar bar;
};

void main()
{
    struct Foo foo;
    PrintString(foo.bar.baz);
}
I wonder if nested structures are allowed on this scripting language? Or is this a bug on wine only?

Comments

  • ProlericProleric Member Posts: 1,316
    Nested structures are not supported.

    However, built-in structures like vector, effect and location can be used as elements.
  • SherincallSherincall Member Posts: 387
    Nested structures work with nwnsc, if that's acceptable for you: https://neverwintervault.org/project/nwnee/other/tool/nwnsc-nwn-enhanced-edition-script-compiler
  • virusmanvirusman Member, Developer Posts: 173
    This is now supported by the Toolset, starting with 8193.10.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    While that is great news it means I have to start rewriting something I have worked off and on for over a year. Cest la vie.

    TR
  • FreshLemonBunFreshLemonBun Member Posts: 909
    At long last.
  • virusmanvirusman Member, Developer Posts: 173
    By the way, nwnsc does not actually support nested structures: it doesn't stop with an error, but it compiles incorrect code for nested structs.
  • fot1fot1 Member Posts: 74
    @virusman I've tried to put up a simple int list, but unfortunately the toolset break when trying to compiling it. The attached gif shows it breaking, and I'm pasting the file contents here for simplicity.

    I'm using nwn through steam, lastest update, and in the toolset about I see game version v1.80 and toolset
    version vts80.

    What am I doing wrong?


    tkg0smdbifeq.gif

    struct IntList {
        int intialized;
        int value;
        struct IntList next;
    };
    
    struct IntList IntAppend(struct IntList list, int value) {
        struct IntList newNode;
        newNode.initialized = 1;
        newNode.value = value;
    
        if(list.initialized == 0)
            return newNode;
    
        struct IntList i;
        while(i.next.initialized == 1) {
            i = i.next;
        }
    
        i.next = newNode;
        return list;
    }
    
    void PrintIntList(struct IntList list) {
        struct IntList i;
        while(list.initialized) {
            PrintString(i.value);
            i = i.next;
        }
    }
    
    
    void main() {
    }
    

  • TarotRedhandTarotRedhand Member Posts: 1,481
    While you can now have structs within structs, I don't believe you can have actual linked lists. What you need to do is to use pseudo lists. A good place to start with understanding them is Scripting Library - (Pseudo) List v.4 by Shadooow over on the vault.

    TR
  • virusmanvirusman Member, Developer Posts: 173
    edited September 2020
    This is not going to work because struct elements are not references, they're actual structs stored within structs. The compiler enters an endless loop when trying to compile the structure that contains itself. Its size is effectively infinite.
Sign In or Register to comment.