Jump to content

[LE] Scripting new "class"


MrKew48

Recommended Posts

Hello,

I want to make some functions to handle multi-dimensional array.

So I would like to create something like new data type with new Properties (for example number of rows and cols) so I created new Script like this:

Scriptname DDGrid Hidden

Int Property Rows Auto
Int Property Cols Auto

function init(int r, int c)
	;some code
endfunction
I dont want any functions from Form or anything else so it extends nothing. And then I would like to access it from any other script. I would imagine something like:

 

DDGrid Grid = new DDGrid
Grid.init(3, 2)

This obviouslly doesnt work. On CK Wiki, there are two ways how to do that, but I can't use any of them. I cant fill Property because it extends nothing (I quess) and I cant cast it with "as" because it doesnt extend same type.

 

Is it even possible to do something like that in papyrus? I cant find much about it on the internet.

 

Thanks for any help

Edited by MrKew48
Link to comment
Share on other sites

No, what you're trying to do there isn't possible. Or at least it's not possible the way you're trying to do it. Generally if you're trying to create new data types you're not going to be successful in Papyrus. It's not a general purpose programming language.

 

Papyrus is an object-based language but the way objects are instantiated is very different than general purpose languages.

 

In Papyrus the scripts are the equivalent of classes and provide object definitions. At least that much is similar, but any script which doesn't extend Form (or one of it's sub-classes) can never have an object instance. Examples of the non-extending classes are Game, Utility, and Math. This type of script can have class-level functions and constant properties but no events or variables.

 

Script instances can have variables, events, etc. but a script instance can only exist when attached to a game object. All game objects extend Form. Some forms (like quests) can only have a single instance (and it's usually persistent). Others can have as many instances as there are matching objects in the game world.

 

In theory you can have your grid script attached to some particular game object which you can then instantiate as needed but those instances either have to be persistent or in a loaded cell for the script to be available.

 

On a technical level you can't create dynamically sized arrays and arrays created by script are limited to 128 values so there's very little benefit to the idea of a 2D array object.

 

People interested in more generic data structures like you're proposing have created them using SKSE plugins, but in general a new language usually means a need for new approaches to solving problems. In my opinion (and experience) it's better to come up with a new solution to a problem using the existing features in Papyrus rather than rebuild structures to fit the solution you would have used in other languages.

Link to comment
Share on other sites

Using SKSE it's possible to create dynamically sized arrays of arbitrary size, which can be used to implement multi-dimensional arrays. You could hide all the work in a global script with a set of functions that take an array and indices as input and returns appropriate output (e.g. resizing, sorting, returning the value). You lose, though, a lot of the advantage of using arrays over other solutions, which is their speed.

Link to comment
Share on other sites

Papyrus can't be approached like it's C++, C, Python, Perl, Java, JS, etc.

 

The creator of papyrus didn't design it to be a full fledged programming language(and C++ was used to make Skyrim). It was just for the puzzles and such.

Edited by Rasikko
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...