Jump to content

Adding Object References to array


Fliteska

Recommended Posts

I've made 2 scripts, one is a quest to hold some data, the other is object reference just to add data to the quest... I can't seem to figure out what is wrong with the following code but my BuiltInstances array length doesn't change when I add an item into it. The notifications appear but just says Length = 0. Everything compiles fine, but can't figure out whats wrong... any ideas?

 

ScriptName TeleporterManagerScript extends Quest

ObjectReference[] Property BuiltInstances Auto Const

Function Add(ObjectReference akRef)
BuiltInstances.Add(akRef)
Debug.Notification("Adding... Length = " + BuiltInstances.Length)
EndFunction

Function Remove(ObjectReference akRef)
Debug.Notification("Removing... Length = " + BuiltInstances.Length)
int i = BuiltInstances.Find(akRef)
If (i >= 0)
BuiltInstances.Remove(i)
EndIf
EndFunction

Function Teleport()
If (BuiltInstances.Length > 0)
Debug.Notification("Teleport")
int rInt = Utility.RandomInt(0, BuiltInstances.Length)
Game.GetPlayer().MoveTo(BuiltInstances[rInt])
EndIf
EndFunction

 

Scriptname TeleporterActionScript extends ObjectReference

TeleporterManagerScript property ManagerEffect auto const

Event OnActivate(ObjectReference akActionRef)
If akActionRef == Game.GetPlayer()
ManagerEffect.Teleport()
EndIf
EndEvent

Event OnWorkshopObjectPlaced(ObjectReference akRef)
ManagerEffect.Add(akRef)
EndEvent

Event OnWorkshopObjectDestroyed(ObjectReference akRef)
ManagerEffect.Remove(akRef)
EndEvent
Link to comment
Share on other sites

I would say that it happens because the property is flagged as constant.

But I won't use a property for an array that is going to be changed in run time, I would declare it and initialize at OnQuestInit.

ScriptName TeleporterManagerScript extends Quest

;Declare the array
ObjectReference[] BuiltInstances

Event OnQuestInit()
	;initialize the array
	BuiltInstances = new ObjectReference[0]
EndEvent

Function Add(ObjectReference akRef)
    BuiltInstances.Add(akRef)
    Debug.Notification("Adding... Length = " + BuiltInstances.Length)
EndFunction

Function Remove(ObjectReference akRef)
    Debug.Notification("Removing... Length = " + BuiltInstances.Length)
    int i = BuiltInstances.Find(akRef)
    If (i >= 0)
        BuiltInstances.Remove(i)
    EndIf
EndFunction

Function Teleport()
    If (BuiltInstances.Length > 0)
        Debug.Notification("Teleport")
        int rInt = Utility.RandomInt(0, BuiltInstances.Length)
        Game.GetPlayer().MoveTo(BuiltInstances[rInt])
    EndIf
EndFunction
Link to comment
Share on other sites

Will give that a go, I did try it without the Const assignment but no luck. Had a feeling it might be the fact it was a Property that was passed into the script rather than something made inside of the script.

 

Edit: Thanks very much, that sorted the problem

Link to comment
Share on other sites

  • Recently Browsing   0 members

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