Fliteska Posted August 30, 2020 Share Posted August 30, 2020 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 QuestObjectReference[] Property BuiltInstances Auto ConstFunction Add(ObjectReference akRef) BuiltInstances.Add(akRef) Debug.Notification("Adding... Length = " + BuiltInstances.Length)EndFunctionFunction Remove(ObjectReference akRef) Debug.Notification("Removing... Length = " + BuiltInstances.Length) int i = BuiltInstances.Find(akRef) If (i >= 0) BuiltInstances.Remove(i) EndIfEndFunctionFunction Teleport() If (BuiltInstances.Length > 0) Debug.Notification("Teleport") int rInt = Utility.RandomInt(0, BuiltInstances.Length) Game.GetPlayer().MoveTo(BuiltInstances[rInt]) EndIfEndFunction Scriptname TeleporterActionScript extends ObjectReferenceTeleporterManagerScript property ManagerEffect auto constEvent OnActivate(ObjectReference akActionRef) If akActionRef == Game.GetPlayer() ManagerEffect.Teleport() EndIfEndEventEvent OnWorkshopObjectPlaced(ObjectReference akRef) ManagerEffect.Add(akRef)EndEventEvent OnWorkshopObjectDestroyed(ObjectReference akRef) ManagerEffect.Remove(akRef)EndEvent Link to comment Share on other sites More sharing options...
DieFeM Posted August 30, 2020 Share Posted August 30, 2020 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 More sharing options...
Fliteska Posted August 30, 2020 Author Share Posted August 30, 2020 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 More sharing options...
Recommended Posts