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? Is this behaviour limited to EE? 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?
TR
not a bug, missing functionality, EE didn’t change anything in this regard
This was a well-documented issue with NWN from the outset. Nested structs don’t work.
A possible workaround is to expand the fields in the nested struct, then assign field by field. Another technique is to convert the simple struct contents to a delimited string, though I don’t think that helps much unless there are a vast number of fields in the struct.
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.
TR
Yes, exactly that access violation was reported long ago.
I haven’t coded for NWN and my coding knowledge is from a very long time ago, but I have an idea. What if you put a pointer to uFirst inside uSecond, instead of an actual uFirst? You would have to create a uFirst variable dynamically and have the pointer point to it.
NWScript doesn’t have pointers. It only looks like C …