Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Neverwinter Nights: Enhanced Edition has been released! Visit to make an order. NWN:EE FAQ is available.
Soundtracks for BG:EE, SoD, BG2:EE, IWD:EE, PST:EE are now available in the Beamdog store.
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Is this a bug or expected behaviour.

TarotRedhandTarotRedhand Member Posts: 563
edited October 11 in General Discussions NWN:EE
I am currently doing some research and stumbled across something. I created a pair of structs -
struct uFirst
	int a;
	float b;
	string c;

struct uSecond
	struct uFirst d;
	int e;
And tested to make sure there were no syntax or other errors. The toolset compiler had no trouble with that. However whenever I try to use struct d in uSecond even to just assign another instance of struct uFirst to it I get an access violation error. Is this a bug? In C/C#/C++ what I am trying to do is perfectly valid and also it must be processed when you use an NwN variable of type location too. Ideas?




  • TarotRedhandTarotRedhand Member Posts: 563
    edited October 11
    I have been told elsewhere that this is due to missing functionality in the way that NwN handles structs. The silly thing is that I fixed one access violation error condition but then encountered a new one. Try this script -

    struct uFirst { int a; float b; string c; }; struct uSecond { struct uFirst d; int e; }; struct uFirst AFunction() { struct uFirst uReturnMe; uReturnMe.a = 1; uReturnMe.b = 2.0f; uReturnMe.c = "Three"; return uReturnMe; } int GetInt(struct uFirst uTest) { return uTest.a; } void main() { struct uFirst uVar = AFunction(); struct uSecond uVar2; int iTest; uVar2.e = 5; uVar2.d = uVar; //iTest = GetInt(uVar2.d); }
    Saved/Compiled as is works fine. Now uncomment that last line and you’ll get an access violation. It appears you can put data into a nested struct, you just can’t get it out again.

    Seeing as the built-in data types that are structs (location etc.) have no problem handling this isn't it time that user scripts had the same ability? Being able to handle just a single level of nesting would unlock the true potential of this data type.


  • nivniv Member, Moderator, Developer Posts: 339
    Hey Tarot,

    that's pretty much a known issue with the compiler. It can't do nested structs. We'd have to fix it for this to be viable. So yeah, it's a bug, but it's been that way since the NWN release.

  • thirdmousethirdmouse Member Posts: 67
    Compiling with NWNSC should work, if that's an option.

  • TarotRedhandTarotRedhand Member Posts: 563
    Thanks for the reply @niv . I personally still think it should be fixed sometime though as fixing that would not break backwards compatibility. Actually there is one other little thing with structs. I doubt this next would be an easy fix. With the built in structs a constructor function can have the same name as the type it is constructing. For example -

    vector vVec = Vector(x, y, z);

    It would be nice to be able to do the same thing for constructors for user created structs as well.


Sign In or Register to comment.