Scripting: Arrays - Creating, Populating, and Calling from

Post » Tue Jun 19, 2012 9:30 am

I am putting putting together a mod that will have 10 ranks for a faction (ala morrowind/oblivion) and I am working through the scripts section on the wiki... sadly, it's not as populated as I need, and my script-fu is rusty as hell (I'm discovering :stare: )...

I _think_ I have the concept down, but syntax I'm very unsure of at this point. This is not a full script, this is a 'getting the idea right'

Please tell me if I'm heading the right way or not and if not, where I'm heading wrong.

3 bits: 1, Variables for the Array, 2. Actual array creation, and 3. getting info from the array...


1. Variables for array - Sets variable string "CoWRanks" for array CoWFactRank, specifying the 10 ranks in the array

String CoWRanks={"Novice", "Initiate", "Apprentice", "Journeyman", "Adept", "Magician", "Expert", "Wizard", "Master", "Arch-Mage"}


2. Array Creation - Creates the CoWFactRank, Tells it there's 10 ranks, and defaults it to array index 0 (String "Novice")

CoWFactRank[] x = new Novice[10]


3. Calling a specific rank from the array - This would return the value "Journeyman" from the CoWFactRank array

CoWRanks = CoWFactRank[3]
User avatar
Veronica Martinez
 
Posts: 3498
Joined: Tue Jun 20, 2006 9:43 am

Post » Tue Jun 19, 2012 12:37 am

That string array won't work, as it's not defined as an array and, as far as I know, there's no way to assign multiple elements of an array in a single assignment like that.

Also note that, because the only initialisation you can do outside of any functions (including events) is to a literal, so you'll have to set up your array in something like an http://www.creationkit.com/OnInit event.

Try something like this:
string[] CoWRanks; Inside an event or other function...CoWRanks = string[10]CoWRanks[0] = "Novice"CoWRanks[1] = "Initiate"; And so on...

Does that help you?

Cipscis
User avatar
M!KkI
 
Posts: 3401
Joined: Sun Jul 16, 2006 7:50 am

Post » Mon Jun 18, 2012 10:59 pm

Now that I've completed my Node porting spell, more or less as I envisioned it (still wish I could have gotten it to track a moving target smoothly), I'll probably be turning my attention to trying to figure out how to implement a dynamically created linked list, with no persistant reference variables. And some way of storing information when the player is outside a cell so that randomly determined things (Like the combination for a door) will be different in each runthrough, but consistant once determined (once you open the box, the cat either stays dead or alive...or in this case, the sequence of levers remains up, down, down, down, up, down, while the sequence on your OTHER character has it as down, down, up, down, down, down)
User avatar
ChloƩ
 
Posts: 3351
Joined: Sun Apr 08, 2007 8:15 am

Post » Tue Jun 19, 2012 11:51 am

That won't work. Something like this might work (note: not 100% on Papyrus syntax)
String[] CowFactRank = new String[10]; declare array	;;;;;;;;;;;;;;;;;;;;;;;;;; Assign values to arrayCowFactRank[0] = "Novice"CowFactRank[1] = "Initiate"CowFactRank[2] = "Apprentice"CowFactRank[3] = "Journeyman"CowFactRank[4] = "Adept"CowFactRank[5] = "Magician"CowFactRank[6] = "Expert"CowFactRank[7] = "Wizard"CowFactRank[8] = "Master"CowFactRank[9] = "Arch-Mage";;;;;;;;;;;;;;;;;;;;;;;;;String CoWRank = CoWFactRank[3] ; Assign "Journeyman" to variable CoWRank

Unfortunately, I don't think Papyrus supports assigning all elements of an array at once (like you would in, say Java or C++, using int[] var = {1,2,3,...,n}; )

Edit: Ninja'd...
User avatar
CxvIII
 
Posts: 3329
Joined: Wed Sep 06, 2006 10:35 pm

Post » Mon Jun 18, 2012 11:31 pm

okay, that helps yes (and I was afraid doing it like I was, ala c++ style wouldn't work *sigh*)... I have some additional (okay lots ::P) more questions to come... after I sleep... What I had typed didn't make sense to me, so I'm sure it wouldn't have made sense to anyone else. :x
User avatar
Joey Bel
 
Posts: 3487
Joined: Sun Jan 07, 2007 9:44 am

Post » Tue Jun 19, 2012 12:40 am

okay, that helps yes (and I was afraid doing it like I was, ala c++ style wouldn't work *sigh*)... I have some additional (okay lots : :tongue:) more questions to come... after I sleep... What I had typed didn't make sense to me, so I'm sure it wouldn't have made sense to anyone else. :x

It wouldn't be easier to make it a Property?

That would allow you to make a more generic script (which you could cannibalize) and from outside the script you can declare the content of the array in the Property window...
Jashkar
User avatar
Ron
 
Posts: 3408
Joined: Tue Jan 16, 2007 4:34 am


Return to V - Skyrim