Assigning starting values for long arrays?

Post » Wed Jun 20, 2012 7:38 pm

Has anyone figured out how to assign a bunch of values to an array without doing something like this?

   bool[] TurnLeft = new Bool[128] ; A list of instructions to either turn left or right...false is a right turn.   TurnLeft[0] = False   TurnLeft[1] = False   TurnLeft[2] = True   TurnLeft[3] = False   TurnLeft[4] = False   TurnLeft[5] = True   TurnLeft[6] = False   TurnLeft[7] = False   TurnLeft[8] = False   TurnLeft[9] = True   TurnLeft[10] = False   TurnLeft[11] = False   TurnLeft[12] = True   TurnLeft[13] = False...   TurnLeft[125] = False   TurnLeft[126] = True   TurnLeft[127] = True

In "real" programming languages, you could do something like this:

   bool[] TurnLeft = new Bool[128] ; A list of instructions to either turn left or right...false is a right turn.   TurnLeft = {False, False, True, False,False, True, False, False, False,True,False,False, True, False, ... False, True, True}

That's pseudocode, but you get the idea of what I would like to avoid...
User avatar
Spooky Angel
 
Posts: 3500
Joined: Thu Aug 10, 2006 5:41 pm

Post » Wed Jun 20, 2012 7:39 pm

pffft, we just got += and stuff like that. You could at least do only the true ones since it's false by default right? Are these values dynamic, or just stored for use as constants by the script?
User avatar
Mackenzie
 
Posts: 3404
Joined: Tue Jan 23, 2007 9:18 pm

Post » Wed Jun 20, 2012 2:11 pm

pffft, we just got += and stuff like that. You could at least do only the true ones since it's false by default right? Are these values dynamic, or just stored for use as constants by the script?

It's a list of directions for a number of dwemer robots...I want to be able to set their behavior based on a series of linked "Navigation nodes" in the dungeon, and have each robot have it's own series of directions, which it will repeat. But I want each robot to be able to use most of the same nodes, so I want to be able to give each robot a set of arrays that define where it will go at each stage of it's programmed patrol. Each node has a "Forward", "Left", and "Right" link, and when a robot reaches a node, it should increment the "which instruction do I follow" counter, and read in the booleans "turn Left", "Turn Right" and a float "Wait Time" (how long it should wait before it goes to the next node, which can be different for each robot) so, to give a very short example with arrays of only size 5, one robot might need (if "turn Right" and "Turn Left" are both false, it goes straight):

TurnLeft: True, True, False, False, True
TurnRight: False, False, True, False, False
Wait Time: 10.0,5.0,0.0,5.0,20.0

while another robot might need this:

TurnLeft: False, False, False, False, False
TurnRight: True, False, True, False, True
Wait Time: 0.0,5.0,2.0,5.0,20.0

These values would be set in the OnInit() event for the map objects, and can't (obviously) be set in any sort of loop, since they're not in any way computable by the game.
User avatar
Love iz not
 
Posts: 3377
Joined: Sat Aug 25, 2007 8:55 pm

Post » Wed Jun 20, 2012 8:51 am

And yes, I know how to set up ping pong and looping patrols, but I want to have a lot of variation, and I don't want my dungeon to have stacks of idlemarkers ten miles high when It can get away with a few dozen markers and a list of instructions.
User avatar
Rachael Williams
 
Posts: 3373
Joined: Tue Aug 01, 2006 6:43 pm

Post » Wed Jun 20, 2012 8:05 am

Once SKSE has papyrus support, I dare say we can all abandon it's awful array's. And use proper collections/containers instead; someone just has to port/implement them. Worst case scenario, I do it myself.

In the meantime, if you need array's, something like this can (at least potentially) ease some of the pain:
Spoiler
; Note: untestedint function ArrayFlipFlags(bool[] array, int[] indicies = none, int offset = 0, int count = 0, int step = 1) global	int flipped = 0	if (indicies)		int i = 0		while (i < indicies.length)			bool flag = array[indicies[i]]			array[indicies[i]] = !flag			flipped += 1			i += 1		endwhile	endif	if (count > 0)		int i = offset		while (i < count)			bool flag = array[i]			array[i] = !flag			flipped += 1			i += step		endwhile	endif	return flippedendfunction

If anyone is wondering how useless they are: There is not a single vanilla script using an array.
Any regex capable http://www.mythicsoft.com/page.aspx?type=agentransack&page=home or http://www.sublimetext.com/ will be your friend to verify this.
User avatar
Verity Hurding
 
Posts: 3455
Joined: Sat Jul 22, 2006 1:29 pm

Post » Wed Jun 20, 2012 5:02 am

It's not the arrays that are the problem, it's assigning them values in a single line, rather than one. Item. At. A. time. One. per. Line.
User avatar
Bad News Rogers
 
Posts: 3356
Joined: Fri Sep 08, 2006 8:37 am

Post » Wed Jun 20, 2012 5:41 pm

I suppose I'll have to write functions that are called like this:

Function InitialiseBool10(Array BoolArray,int StartElement,Bool Element1,Bool Element2,Bool Element3,Bool Element4,Bool Element5,Bool Element6,Bool Element7,Bool Element8,Bool Element9,Bool Element10)
User avatar
Prohibited
 
Posts: 3293
Joined: Tue Jun 12, 2007 6:13 am

Post » Wed Jun 20, 2012 5:55 am

@Xetrill, CompanionsBladeFragmentTracking.psc <-- Uses arrays.

That's the only one in the game afaik. There are some good comments around the code though mentioning the lack of arrays :smile:

Edit: Now my eyes are bleeding. I just looked at FormArray.psc.
User avatar
Charlie Sarson
 
Posts: 3445
Joined: Thu May 17, 2007 12:38 pm

Post » Wed Jun 20, 2012 4:50 pm

how about, for each individual instance of the script, on each mob, have the values filled something like this:

for i= 1 to 128
if randomnumber() > 60 (or .6, or whatever)
j = 1
else
j= 0
directions[i] = j
loop

obviously i'm making no attempt to translate into papyrus, but get the idea? each mobs directions are generated at startup. If you needed to get fancy, you could add a few controls based on property you set for each one. Like:

int property patroltype auto
{ 0 = random, 1 = stay in middle, 2 = outer wall only}

then do some logic to bring that about in your goofy directions.
User avatar
stephanie eastwood
 
Posts: 3526
Joined: Thu Jun 08, 2006 1:25 pm

Post » Wed Jun 20, 2012 4:06 am

how about you put some functions on the mobs, causing them to take certain actions(go left, go right, etc...), then have triggers at the points of 'choice' that call the functions on the triggering mob based on preset properties of the mob. You could also use properties of the triggers in your trigger script to tell the trigger what sort it is, like whether it has an open path to the east, west, north, or south of it. I'm still not very clear on what you're actual goal is. How much will this add to the mod? Will anyone notice the difference between this and a patrolling pat? these are questions for you. If it's just to do it, an experimental exercise modding is as good as any reason :biggrin:
User avatar
Crystal Clarke
 
Posts: 3410
Joined: Mon Dec 11, 2006 5:55 am

Post » Wed Jun 20, 2012 12:25 pm

Redwood Elf
Array's are initialized to the default value of their type, so you only have to set those indices for which you want another value. That's why I wrote ArrayFlipFlags as it is.

tunaisafish
Hmm missed that one. So, array's are used a total of 1 times by Bethesda themselves.

And FormArray is ... nevermind. But used only once in CWResetScript which is commented to be obsolete anyway.
User avatar
Thomas LEON
 
Posts: 3420
Joined: Mon Nov 26, 2007 8:01 am


Return to V - Skyrim