Loogie Posted July 17, 2017 Posted July 17, 2017 Maybe not the best place to ask this, and maybe it's not doable, but if I've created an array full of NPCs, what is the best way to randomly assign one of the values in the array to a ref variable? I'm experimenting with different ways for the Tryout scanner to pick companions for sex, and I can't figure out how to script this.
DoctaSax Posted July 17, 2017 Posted July 17, 2017 I assume you mean: how to pick a random NPC ref from a bunch held in an array? try this: int iKey int iSize ref rNPC let iSize := ar_size MyArray set iKey to rand 0, iSize let rNPC := MyArray[iKey]
Loogie Posted July 17, 2017 Author Posted July 17, 2017 I gave this a shot - it says the "let" command resulted in an invalid operation. It's not clear which "let" statement it's squawking about, but it has to be one of those two as they are the only ones in the script. But, it looks like this is also going to use more scripting to initialize the array and populate it than the other way I was planning on doing it. If I can get it working, there's a bunch of other applications for this, though, like partnering up people from two different arrays.
DoctaSax Posted July 17, 2017 Posted July 17, 2017 Could be something as simple as a typo. The only possible reasons for an error in those lines are 1. The array isn't initialized 2. It is, but there's nothing under that key 3. There is something under that key but it's not a form/ref Try debugging by printing out the value of iKey once it's been calculated, and dumping the contents of the array with ar_dump.
Loogie Posted July 18, 2017 Author Posted July 18, 2017 Could be something as simple as a typo. Yep. It fucking works! Thanks! It's a little more scripting than the other method I was trying to use (some trickery with formlists and tokens), but it runs faster and is far more reliable!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.