Array/data structures library/plugin?
Moderators: Moderator, Developer, DM
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Array/data structures library/plugin?
Does anyone know of some library or plugin for the toolset that adds arrays/data structures to NWScript? Maybe someone out there made a DLL for it or something?
Edit: Found array support.
http://sourceforge.net/projects/stdnws/files/
Edit: Found array support.
http://sourceforge.net/projects/stdnws/files/
Last edited by gedweyignasia on Sun Feb 08, 2015 6:50 pm, edited 1 time in total.
-
NegInfinity
- Posts: 2449
- Joined: Wed Feb 05, 2014 11:24 am
Re: Array/data structures library/plugin?
AFAIK, it supports simple structures.
There's also SetLocalArrayInt/SetLocalArrayString line of functions.
It is unlikely that there is a library that adds proper arrays into core language, cause you need to hook the parser for that, which is gonna be very hard.
Code: Select all
struct strTint
{
int iRed;
int iGreen;
int iBlue;
int iAlpha;
};
It is unlikely that there is a library that adds proper arrays into core language, cause you need to hook the parser for that, which is gonna be very hard.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Re: Array/data structures library/plugin?
I'm looking for something that adds 2-dimensional arrays and hopefully some other data structures like linked lists, tree structures, etc. into the language.
It doesn't have to be "proper" arrays, I just have to know the size of it and be able to access. You don't need any fancy hooks to change the syntax, just give me a way to create 2-dimensional arrays.
To make a faction system pretty, it'd be nice to have an array of objects or an array of creatures.
It doesn't have to be "proper" arrays, I just have to know the size of it and be able to access. You don't need any fancy hooks to change the syntax, just give me a way to create 2-dimensional arrays.
To make a faction system pretty, it'd be nice to have an array of objects or an array of creatures.
-
NegInfinity
- Posts: 2449
- Joined: Wed Feb 05, 2014 11:24 am
Re: Array/data structures library/plugin?
I suggest to try jamming whatever it is you're trying to do into MySQL database. nwnx4 server has sql support via either mysql or sqlite. This will save you from working with arrays in language that doesn't have them.
Emulating arrays via plugin will be difficult, because it is a scripting language. You COULD write a dll that provides you arrays, but you'll need to explicitly manage lifetimes of those arrays, otherwise you'll get massive memory leaks, fast, and manually managing lifetime of anything in nwnscript is gonna be painful.
You have GetLocalArrayInt/String line of functions. Which kinda gives you 1d array. When you have 1d array, you can emulate array of any size with it.
To emulate 2d array (numRows, numColumns) using 1d array, you need 1d array with size numRows*numColumns. Offset of individual element will be column + row*numColumns.
However...
in nwn script there is no debugger. Which means that if you try to do heavy-duty programming there, it is gonna be painful.
I suggest to look at sql-based solution.
I suggest to take a look at 2da files. Get2DAString. You put all data you need into text file *.2da, and then you can access that from within script.gedweyignasia wrote:I'm looking for something that adds 2-dimensional arrays and hopefully some other data structures like linked lists, tree structures, etc. into the language.
It doesn't have to be "proper" arrays, I just have to know the size of it and be able to access. You don't need any fancy hooks to change the syntax, just give me a way to create 2-dimensional arrays.
To make a faction system pretty, it'd be nice to have an array of objects or an array of creatures.
Emulating arrays via plugin will be difficult, because it is a scripting language. You COULD write a dll that provides you arrays, but you'll need to explicitly manage lifetimes of those arrays, otherwise you'll get massive memory leaks, fast, and manually managing lifetime of anything in nwnscript is gonna be painful.
You have GetLocalArrayInt/String line of functions. Which kinda gives you 1d array. When you have 1d array, you can emulate array of any size with it.
To emulate 2d array (numRows, numColumns) using 1d array, you need 1d array with size numRows*numColumns. Offset of individual element will be column + row*numColumns.
However...
in nwn script there is no debugger. Which means that if you try to do heavy-duty programming there, it is gonna be painful.
I suggest to look at sql-based solution.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Re: Array/data structures library/plugin?
Wow, completely spaced on how to fake 2d-arrays. Thaaaat's a good solution, just have to make functions to access it so there isn't ugly math everywhere.
Still need an object array, unless there's a way to uniquely identify objects that may or may note exist using integers or strings. (It's that or have every object store its own information, which turns into a gross conversation.)
Still need an object array, unless there's a way to uniquely identify objects that may or may note exist using integers or strings. (It's that or have every object store its own information, which turns into a gross conversation.)
-
Luna
- Retired Admin
- Posts: 7945
- Joined: Sat May 16, 2009 3:00 pm
Re: Array/data structures library/plugin?
If you have any luck on array support, let me know.
I wanted one to fix some issue's with Kemo Scry.
Think of like putting everyone's name in array and then sorting it.
I don't remember if I couldn't figure it out or just didn't have time to look into arrays further.
I wanted one to fix some issue's with Kemo Scry.
Think of like putting everyone's name in array and then sorting it.
I don't remember if I couldn't figure it out or just didn't have time to look into arrays further.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Re: Array/data structures library/plugin?
Oh, that's a thought... You'd want to sort by various columns? (Each row is a struct, I'd imagine, you'd want to be able to populate an array with a given field, sort by that, then rearrange the structs to display in that order?)Luna wrote:If you have any luck on array support, let me know.
I wanted one to fix some issue's with Kemo Scry.
Think of like putting everyone's name in array and then sorting it.
I don't remember if I couldn't figure it out or just didn't have time to look into arrays further.
-
Luna
- Retired Admin
- Posts: 7945
- Joined: Sat May 16, 2009 3:00 pm
Re: Array/data structures library/plugin?
Nah, just sort it alphabetically.
Throw everyone's name into the array and sort it.
Which from a programming language point of view is a pretty dang simple thing to do.
But I don't know how to do arrays in nwn2.
Throw everyone's name into the array and sort it.
Which from a programming language point of view is a pretty dang simple thing to do.
But I don't know how to do arrays in nwn2.
-
NegInfinity
- Posts: 2449
- Joined: Wed Feb 05, 2014 11:24 am
Re: Array/data structures library/plugin?
I still highly recommend to look into databases. Because for faction it is a natural way to represent things.gedweyignasia wrote:Wow, completely spaced on how to fake 2d-arrays. Thaaaat's a good solution, just have to make functions to access it so there isn't ugly math everywhere.
Still need an object array, unless there's a way to uniquely identify objects that may or may note exist using integers or strings. (It's that or have every object store its own information, which turns into a gross conversation.)
tables:
factions (faction name, faction id, faction description)
members (faction id, member id)
relations (faction id, faction id, relation type)
This kind of thing. Much more natural than arrays. Will persist across resets easily, too.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Re: Array/data structures library/plugin?
I thought database access/modification was a slow/memory-intensive operation in NWN? If not, it'd be ideal for doing a faction system; otherwise you'd basically be writing a crummy database in NWScript.
-
NegInfinity
- Posts: 2449
- Joined: Wed Feb 05, 2014 11:24 am
Re: Array/data structures library/plugin?
I'm talking about SQL database (sqlite/mysql), not NWN database.gedweyignasia wrote:I thought database access/modification was a slow/memory-intensive operation in NWN? If not, it'd be ideal for doing a faction system; otherwise you'd basically be writing a crummy database in NWScript.
Take a look at nwnx4 demo modules. They have sql examples.
-
Rasael
- Retired Staff
- Posts: 8096
- Joined: Wed Jun 30, 2010 6:52 am
- Location: Leiden, Netherlands
Re: Array/data structures library/plugin?
A database read / write is always more expensive in NWN2 than a local read write of a variable to an item.
It gets more expensive also if you try to store objects. Ints, strings and floats are pretty optimized. But objects require more memory. Both in SQL SCOR/CO as with the campaign database. As Ivan wrote BG uses SQL for object storage.
A faction system could probably best be done by storing it on the kemo scry item. And then the first time it is used by a PC / NPC relationship you copy those variables onto the PC himself. To avoid searching the inventory for the kemo item all the time. On logout you can just transcribe it back onto the kemo. Or on-rest. (or both, even better)
The real issue lies in the NPC reactions. Because players can't actually belong to another faction than the PC faction. And the faction related functions don't all work, or work in unexpected ways. (not as they should). That's what caused Ivan much grief when he wrote his code for it. It doesn't work like in NWN1.
I've been meaning to take a look at his code and tinker with it. To see if I can get it working.
It gets more expensive also if you try to store objects. Ints, strings and floats are pretty optimized. But objects require more memory. Both in SQL SCOR/CO as with the campaign database. As Ivan wrote BG uses SQL for object storage.
A faction system could probably best be done by storing it on the kemo scry item. And then the first time it is used by a PC / NPC relationship you copy those variables onto the PC himself. To avoid searching the inventory for the kemo item all the time. On logout you can just transcribe it back onto the kemo. Or on-rest. (or both, even better)
The real issue lies in the NPC reactions. Because players can't actually belong to another faction than the PC faction. And the faction related functions don't all work, or work in unexpected ways. (not as they should). That's what caused Ivan much grief when he wrote his code for it. It doesn't work like in NWN1.
I've been meaning to take a look at his code and tinker with it. To see if I can get it working.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4
Re: Array/data structures library/plugin?
Couldn't you manage how much you wanted a PC to be liked/disliked, and use Personal Reputation instead of faction reputation to make a PC disliked when necessary?
-
Rasael
- Retired Staff
- Posts: 8096
- Joined: Wed Jun 30, 2010 6:52 am
- Location: Leiden, Netherlands
Re: Array/data structures library/plugin?
I think ivan found weird behaviour with that. It is my choice of approach. But i think i remember him saying it didnt work on all creatures.
-
gedweyignasia
- Custom Content
- Posts: 1353
- Joined: Sat Nov 23, 2013 11:27 pm
- Location: EST/UTC-4