Jump to content

Understanding dynamic array correctly


SMB92

Recommended Posts

  On 6/3/2017 at 4:40 PM, SMB92 said:

Despite these arrays not filling/holding my variables, my functions are completing to the end, the debugs are telling me this. Arrays always 0 length but. Well, on the version that has the struct array as a property, as previously said i get weird results. Now with the dynamic struct array it doesnt hold at all.

 

Ok. Assuming I'm using the latest version of your script code I see a few issues. The problems you're having with the arrays is that you initialize them as empty and are not using Add to add new entries. If you want to use the method of adding that you have, then you need to initialize with a starting size.

 

Example:

SomeType[] someArray = new Array[0] ; valid creation but has no entries so length = 0
int iPosition = 0
someArray[iPosition] = someData ; invalid. iPosition = 0. You've never created an index 0 entry in the array so it fails
 
someArray.Add(someData) ; this will create a new entry at the end of the array.
 
;if you want to use the positioner you have to define a size first and increment the counter
SomeType[] someArray = new Array[10] ; create array with 10 indexes starting 0-9
while (iPosition < 10)
    someArray[iPosition] = someData
endwhile

Kitkat81 being confused about the usage of the iPosition variable is understandable because of how it was incorrectly used. The first code snippet that is problematic at first glance is:

 

  Reveal hidden contents

In here you set position to 0, initialize array of 0 length, then try to set the value of an increasing index that doesn't exist. If you swap back in the GroupList.Add line instead of your 2 line Actor akSpawned and GroupList[iPosition] it should go back to building the array.
For the other part of your problem, in the ASC_MasterRandomQuestScript FillArrays() function you have the same problem. You initialize a zero length array and then try to set the value of an index that doesn't exist every time. That function needs to be wholly changed. Try this:
  Reveal hidden contents

Link to comment
Share on other sites

  • Replies 111
  • Created
  • Last Reply

Top Posters In This Topic

This was the latest (a few pages have past since I posted it lol)

 

 

  Reveal hidden contents

 

 

The Add method was doing the same thing, so I just put the 2 line method in there for testing. I'll apply said fixes and test it out again.

 

BTW I am using a clean save game, initializing the mod each time so no funny savegame business :)

Link to comment
Share on other sites

  On 6/4/2017 at 2:42 AM, SMB92 said:

This was the latest (a few pages have past since I posted it lol)

 

[snip]

 

The Add method was doing the same thing, so I just put the 2 line method in there for testing. I'll apply said fixes and test it out again.

 

BTW I am using a clean save game, initializing the mod each time so no funny savegame business :smile:

 

For code readability sake, every place you have '(MasterQuest as ASC_MasterRandomQuestScript)' you can just use MasterQuest because you already cast it when defining the property with 'ASC_MasterRandomQuestScript Property MasterQuest Auto Const'.

 

There could be a lot of things going on about why it's failing. So first I'd ask, does it even spawn an actor at all? Even if it's failing to build the array. Do you have any errors in the papyrus log?

 

The way you're using the loop counter will get it so screwed up if it doesn't have 100% spawn chance. I had a separate counter for the index of the entry on purpose.

 

From your latest code you have

 

[code

GroupList[iSpawnCounter] = akSpawned

[/code]

 

This is going to fail anyway you look at it. As I just mentioned, you never created an entry in the index for it to change. Besides that, the iSpawnCounter is incremented even if the random chance check causes the actor not to spawn. So you're potentially further trying to write to a higher index than should be there.

 

I think there's a way to refactor your 3 spawn functions back down to 1 so you don't have 3 copies of the same code. That just seems inefficient to me. I suppose a simple way would be to use a temp array inside the spawn function. Then at the of the function set one of the real group arrays to be your temp array. This would need a passing of some kind of int and then a simple if/elseif tree to pick which to set. I miss multidimensional arrays. I'll think on that one for a bit. Maybe there's something better out there.

Link to comment
Share on other sites

Well, on the version of the code that uses the struct array as a full property filled in ck, actors spawn but array on object script is always 0. It either spawned no actors, all 4 (maxcount) or 1 boss (maxbosscount). IPosition variable was still intact then.

After i saw your post in the other thread I swapped back to making the struct array dynamic. No spawns at all so far. Originally I still had the iPosition variable intact, after I saw kitcats post and looked at the code again I thought the same thing so I removed it. Same result though. Logs now show Array out of index etc, nothing in the quest scripts array.

I've tried both the .Add method and my 2 assigning lines of code, same result. I just wanted to be sure that wasn't it.

I totally get everything you've advised, I'll be sitting down at the PC in 10 minutes to clean it up with mentioned fixes.

Also the idea of the 3 functions is to have 3 separate arrays of enemies, for the reroll function. I wanted to have more than 1 opportunity to reroll for users who might have good enough rigs to afford large scale vattoes from time to time. I am not happy with the way it is myself, but that was the best way I could come up with. EDIT; Yeah sorry, would be good if that could be rolled into 1 function safely.

 

Edit; By the way, with the version of code that had the struct array as a full property, I actually did try initializing the array at a value of 10, so it would have 11 slots, just to see if it would fill with either method. Still was 0. Just thought it was worth a mention.

Link to comment
Share on other sites

Sure give me a sec

 

  On 6/4/2017 at 6:37 AM, BigAndFlabby said:

Any chance you'd be willing to PM me a link to a zipped copy of the mod I could look at. Trying to figure it out piece meal is kind of difficult when you only see part of it.

Link to comment
Share on other sites

You're fixes work! Everything works just fine from what I can tell, the array returns a size, the actors get cleaned up and the chance settings are working, I can get different numbers of npcs at the point. I'm stoked :)

 

I'll stack 10 points together and see what happens :D

Link to comment
Share on other sites

Just a few notes :

GroupList = new Actor[0] ; - you don`t need this line at all, your array was defined under the script properties section.

BigAndFlabby gave the proper example of defining an array, but as you already defined it ouside of functions and events (so you can use it as a storage), you just don`t need to define it again.

You can use his example to create a temporary array inside of the function (in this case you won`t be able to use this array ouside of the function/event where it was defined)

 

You can use "placeatme" to create a temporary actors. I saw vanilla scripts using placeatme with no problems. I don`t see the reason why you need to use placeactoratme and then to run "deletewhenable".

 

If you move all functions to the quest, you can always undate and change the script and it won`t break the mod.

There are different ways to make it work . But for example you can do it this way :

 

Create a reference alias for the marker . When you want to use one of markers to spawn something on them, apply the alias to the marker(ForceRefTo) and then run the spawn function from any script that has the alias defined in properties ( ReferenceAlias Property MyAlias Auto Const):

MyAlias.GetReference().PlaceAtMe(someActor,1)

 

 

The spawning script functions can be moved to reference alias script or to the quest script.

This can reduce the number of script copies in the game to 1.

 

If you just tell the main goals you want to achieve there can be some better ways.

Link to comment
Share on other sites

@SMB92 - I'm aware this looks like I'm rudely interrupting the discussion and going off topic, but I've been following this conversation since I found the thread. Would you object if I tried to get it moved to the CK section? I'm sure other people would be interested in this, but I bet a lot of them don't wander out of the CK forum and a search there wouldn't find this.

 

Hi, BigAndFlabby :)

Link to comment
Share on other sites

  On 6/4/2017 at 5:02 PM, llamaRCA said:

@SMB92 - I'm aware this looks like I'm rudely interrupting the discussion and going off topic, but I've been following this conversation since I found the thread. Would you object if I tried to get it moved to the CK section? I'm sure other people would be interested in this, but I bet a lot of them don't wander out of the CK forum and a search there wouldn't find this.

 

Hi, BigAndFlabby :smile:

Sure, I don't mind at all. I didn't bother to post there as didn't think it was that active.

 

By the way, BnF showed me the errors with the quest script and how to make the struct/array work the way I wanted, and then he refactored the spawn code back down to 2 functions :) So all working again.

 

Now to look into more alias packages, Vertibird attacks and a few other interesting things

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...