Jump to content

Accessing another scripts property values at runtime


Lazauya

Recommended Posts

I want to be able to read property values from another script dynamically, say I have two activators and they share properties and values of properties. Is this possible to do without having them both reference an object in the world? Can I have an int property and have the value of that int be shared between multiple scripts?

Link to comment
Share on other sites

Create a Property in each Activator script that holds the reference of the other.

 

This is why Linked Ref is handy, but it's not very dynamic as you can only create a linked ref in the CK render window (eg: the items already have a object reference and exist in the game world when the game loads).

 

For example:

In game at runtime I want the player to spawn a planter soil that the player can plant stuff in to grow.

 

Planter soil is made of 2 parts, 1 part the activator soil which is linked to a 2nd part a NPC in a utility cell.

In CK You would drop the soil in the render window and drop a planter NPC in the utility cell.

Then you would create a linked ref from the Soil to the Planter NPC.

The scripts attached to each item set their variables to each other based on the Linked Ref.

 

I did say I want to dynamically spawn the Soil at runtime while in the game.

 

So another way instead of relying on a Linked Ref (since I can't create those at runtime in game) is:

In CK I create a new Activator form in the Object Window which is my soil.

In CK I create a new NPC Actor in the object window which is my Planter NPC.

 

I attach a script to my new my Soil Activator in the Object window.

In my Soil Script I add an empty Objectreference Property eg:

 

Objectreference Property PlanterNPCRef Auto Hidden

 

I attach a script to my Planter NPC in the Object Window.

In my Planter script I add an empty Objectreference Property eg:

 

Objectreference Property SoilRef Auto Hidden

 

Now when I spawn the soil and planter npc in the game by using placeatme I fill the Properties in the object script of each item after each is spawned.

 

If you would like a working example of the above then ask away.

 

I've done similar with book shelves, display cases and weapon racks and plaques.

Since all these items depend on using a linked ref and it makes it so you can't dynamically spawn and place them in game as wanted on the fly.

By using a bit of trickery and script work you can make just about any item (not all) that normally depends on hard set linked refs null avoid.

In turn making those items able to dynamically be spawned as required at runtime.

Link to comment
Share on other sites

Create a Property in each Activator script that holds the reference of the other.

 

This is why Linked Ref is handy, but it's not very dynamic as you can only create a linked ref in the CK render window (eg: the items already have a object reference and exist in the game world when the game loads).

 

For example:

In game at runtime I want the player to spawn a planter soil that the player can plant stuff in to grow.

 

Planter soil is made of 2 parts, 1 part the activator soil which is linked to a 2nd part a NPC in a utility cell.

In CK You would drop the soil in the render window and drop a planter NPC in the utility cell.

Then you would create a linked ref from the Soil to the Planter NPC.

The scripts attached to each item set their variables to each other based on the Linked Ref.

 

I did say I want to dynamically spawn the Soil at runtime while in the game.

 

So another way instead of relying on a Linked Ref (since I can't create those at runtime in game) is:

In CK I create a new Activator form in the Object Window which is my soil.

In CK I create a new NPC Actor in the object window which is my Planter NPC.

 

I attach a script to my new my Soil Activator in the Object window.

In my Soil Script I add an empty Objectreference Property eg:

Objectreference Property PlanterNPCRef Auto Hidden

I attach a script to my Planter NPC in the Object Window.

In my Planter script I add an empty Objectreference Property eg:

Objectreference Property SoilRef Auto Hidden

Now when I spawn the soil and planter npc in the game by using placeatme I fill the Properties in the object script of each item after each is spawned.

 

If you would like a working example of the above then ask away.

 

I've done similar with book shelves, display cases and weapon racks and plaques.

Since all these items depend on using a linked ref and it makes it so you can't dynamically spawn and place them in game as wanted on the fly.

By using a bit of trickery and script work you can make just about any item (not all) that normally depends on hard set linked refs null avoid.

In turn making those items able to dynamically be spawned as required at runtime.

 

So then is it possible to do this with a script on a magic effect and another script arbitrarily placed in a cell somewhere?

Sorry that this wasn't mentioned earlier; I assumed that there was just some simple, generic thing I was overlooking that could be used across all forms, but now it seems that there really isn't an easy way to do this.

Link to comment
Share on other sites

There's an easy way to do it.

Scriptname ScriptAName Extends ActiveMagicEffect
{I'm a script on a MGEF}

Int Property somePropertyYouWantToAccess Auto 

;===============================

Scriptname ScriptBName Extends ObjectReference
{I'm a script on a completely unrelated OBJREF}

ScriptAName Property SomePropName Auto 

Function coolStuff()
     SomePropName.somePropertyYouWantToAccess = 2999349
EndFunction

Make sure you fill the property of type ScriptA (the type being the name of the other script).

Link to comment
Share on other sites

  • Recently Browsing   0 members

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