Jump to content

Getting References from Arrays


Recommended Posts

How do I get them out of arrays? I've tried doing so but the game ends up crashing once I try to use it for things like reference.HasSpell someSpell.

 

set RefTempA to GetCrossHairRef

let someArray[index] := RefTempA

...in another quest/script...

let RefTempB := otherQuest.someArray[index]

if RefTempB.GetItemCount Breadloaf > 0 <- this is where it will crash

 

What am I doing wrong?

Link to comment
Share on other sites

Odd. But how do you get to the part where you add the item to array? Also, I think you will need ar_Append if you do not already have element (empty or filled) in someArray[index], but I am not sure. It should work if you first initialise the array (as I think you have done?) and then use ar_Append:

Array_var someArray
ref refTempA
int intTemp
...
let intTemp := ar_Size someArray
If ( intTemp < 0)
    let someArray := ar_Construct Array
    PrintD "YourModPrefix: someArray initialised"
Else
    PrintD "YourModPrefix: someArray size = " + $intTemp
EndIf
...
let refTempA := GetCrosshairRef
If ( refTempA == 0 )
    PrintD "YourModPrefix: No ref at crosshair"
ElseIf ( refTempA.GetObjectType == 35 || refTempA.GetObjectType == 36 ) ; Creature or actor
    ar_Append someArray refTempA
    PrintD "YourModPrefix: Added %q" + $refTempA + "%q to someArray"
EndIf
...
And you could then access it with the index. As you have done:

ref refTempB
int Index
...
let refTempB := otherQuest.someArray[Index]
If ( refTempB == 0 )
    PrintD "YourModPrefix: No ref in someArray[" + $Index + "]"
ElseIf ( refTempB.GetItemCount BreadLoaf > 0 )
    PrintD "YourModPrefix: %q" + $refTempB + "%q has " + ( refTempB.GetItemCount BreadLoaf ) + " bread loafs"
EndIf
I put it that way so that, if you have debug messages on for your project (SetDebugMode 1 in one of your scripts, if you have not yet found the feature), you will see messages in console. If they help.

 

Maybe the crash could have been caused by the game trying to check a 'null' reference in case GetCrosshairRef did not return anything? You do know it only returns the one wihing 'activation' distance (like an apple only if the apple name is visible at crosshair, not an apple from twenty metres away). Also, indexes are [0,(size - 1)], so if an array has one element, the Index of that element is 0 and size of the array 1. Just in case that might be it? I do not know how much you know, but in case you knew, sorry about the basics. :)

 

Other than that, I do not know how it would not work. I hope it is not something too obscure.

Edited by PhilippePetain
Link to comment
Share on other sites

  • Recently Browsing   0 members

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