Jump to content

How to access a script's data from another object with a script?


cheejins

Recommended Posts

Hey yall, I have 2 scripts in Fallout 4 Creation Kit:

 

  • Script A has array properties that point to spawn point markers.
  • Script B needs to act as a global script and contains the logic of spawning NPCs.
  • I need Script B to access script A's XMarker properties so I can spawn NPCs at those markers.

Right now I'm trying to set a ScriptObject property to link the scripts together but am having trouble with this method because it's probably wrong.

 

I'm new to CK and would really appreciate some help with this concept as it's a core feature to a mod I'm trying to make.

 

Thanks.

Link to comment
Share on other sites

Several approaches. I assume your hanging your scripts off of a quest:

 

(a1) In script A define your array as a property so it can be accessed remotely:

Scriptname QuestAScript extends Quest

ObjectReference[] Property ListOfMarkers Auto

;Need to create ListOfMarkers = New ObjectReference[0]
;Need to build  ListOfMarkers.Add(Marker)  

(a2) In script B access the remote script, remembering its a pointer so any changes are actually on the remote array:

Quest Property pQuestA Auto Const Mandatory

Function GetArrayA()
   ObjectReference[] LocalArrayPointer = (pQuestA as QuestAScript).ListOfMarkers
EndFunction 

(b1) Or in script A publish a function that exposes the array

Scriptname QuestAScript extends Quest

ObjectReference[] ListOfMarkers

ObjectReference[] Function GetListOfMarkers() 
   Return ListOfMarkers
EndEvent

(b2) In script B call the remote function

Quest Property pQuestA Auto Const Mandatory

Function MyFunction()
   ObjectReference[] LocalArrayPointer = (pQuestA as QuestAScript).GetListOfMarkers()
EndFunction
Link to comment
Share on other sites

If script A is this

 

Scriptname ScriptA extends Quest 
ObjectReference[] Property SpawnPoints Auto

In Script B do this

Scriptname ScriptB extends Quest 
ScriptA Property ScriptARef Auto
;In the CK, choose the form that ScriptA is attached to

Event SomeEvent()
    ScriptARef.SpawnPoints[0].SomeFunction() 
EndEvent
Link to comment
Share on other sites

 

If script A is this

 

Scriptname ScriptA extends Quest 
ObjectReference[] Property SpawnPoints Auto

In Script B do this

Scriptname ScriptB extends Quest 
ScriptA Property ScriptARef Auto
;In the CK, choose the form that ScriptA is attached to

Event SomeEvent()
    ScriptARef.SpawnPoints[0].SomeFunction() 
EndEvent

 

 

Thanks. This worked exactly how I needed it to.

Link to comment
Share on other sites

 

Several approaches. I assume your hanging your scripts off of a quest:

 

(a1) In script A define your array as a property so it can be accessed remotely:

Scriptname QuestAScript extends Quest

ObjectReference[] Property ListOfMarkers Auto

;Need to create ListOfMarkers = New ObjectReference[0]
;Need to build  ListOfMarkers.Add(Marker)  

(a2) In script B access the remote script, remembering its a pointer so any changes are actually on the remote array:

Quest Property pQuestA Auto Const Mandatory

Function GetArrayA()
   ObjectReference[] LocalArrayPointer = (pQuestA as QuestAScript).ListOfMarkers
EndFunction 

(b1) Or in script A publish a function that exposes the array

Scriptname QuestAScript extends Quest

ObjectReference[] ListOfMarkers

ObjectReference[] Function GetListOfMarkers() 
   Return ListOfMarkers
EndEvent

(b2) In script B call the remote function

Quest Property pQuestA Auto Const Mandatory

Function MyFunction()
   ObjectReference[] LocalArrayPointer = (pQuestA as QuestAScript).GetListOfMarkers()
EndFunction

Thanks for the reply. I will definitely use these ways in the future.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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