Jump to content

Photo

Scripting Help - Calling Properties Between Scripts


  • Please log in to reply
8 replies to this topic

#1
Myst42

Myst42

    Faithful poster

  • Members
  • PipPipPipPip
  • 1,869 posts

Anybody knows how to do this?

 

I have a "ScriptA" ActiveMagicEffect script, with a "Caster" Actor property that is kind of dynamic since the caster can be anyone who casts the spell.

Then I have a "ScriptB" ObjectReference script that needs to know who the Caster in script A is

 

How do I do this?

I can't for the life of me make "GetLinkedRef" function to work, compiler tells me every single iteration of it I've tried is wrong.

 



#2
Reneer

Reneer

    Old hand

  • Supporter
  • PipPipPipPipPip
  • 2,935 posts
You would want something like this for your MGE script (note, this is pseudocode since I'm not at my main computer):
ObjectReference Property MyObj Auto
 
Event OnEffectStart(Actor akTarget, Actor akCaster)
   (MyObj As YourScriptNameHere).PropertyName = akCaster
endEvent

Edited by Reneer, 08 November 2018 - 09:28 PM.


#3
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 7,638 posts

Having the property on the magic effect would cause your objectreference to pull invalid data should the magic effect cease to exist. 

 

Here is another solution:

Spoiler

With the actor property on the objectreference, it can be filled by the magic effect and remain filled even after the magic effect ends and ceases to exist.

 

Even with this, depending upon how and when you wish your script to function, it may be better to utilize a quest script to hold the property.

I can see the following as viable:

Spoiler

 

On the CK wiki the following discusses how to do this in regards to functions. https://www.creation...m_Other_Scripts

The process is the same only substituting property variables in place of functions.



#4
jdrfox

jdrfox

    Regular

  • Members
  • PipPip
  • 76 posts

hmm, how about:

 

ScriptA property myOtherScript auto const            ;;fill this one with your ScriptA id in creation kit

 

 

Event OnEffectStart (Actor akTarget, Actor akCaster)

     Actor newActor = myOtherScript.Caster

endEvent



#5
Myst42

Myst42

    Faithful poster

  • Members
  • PipPipPipPip
  • 1,869 posts

 

 

 

 

 

 

Ah. Thank you all very much.

I think now I get the mechanics of calling properties between scripts

It's really just a matter of "OtherScriptCall.RetrievedProperty right"?

Previous inclusion of the other script as a property itself ofc ("OtherScript'sRealName Property OtherScriptCall Auto")

Curiously, I've been calling functions just like that for a while, but functions use the () on their name so I didn't know the name was enough to get the property

 

Well, the compiling worked

Did the the swap thing, so now the magic effect fills the property on the object reference script instead

 

Found myself with another issue though

The magic effect I was using is strange since it's delivery is "target location" instead of an NPC or something, also the casting is type "Voice"

As a consequence, it generates no events

Been struggling with such thing for a while, I'm just finding out "OnEffectStart" needs to always hit something to exist

Some other issues I had with it relate to wanting a spell to generate a script effect even if the projectile hit no one.

 

As this thing itself proves, a placed object/explosion can call scripts from the ground, but I still have no idea how to make it know who the caster of the spell that placed them was.


Edited by Myst42, 08 November 2018 - 10:56 PM.


#6
Reneer

Reneer

    Old hand

  • Supporter
  • PipPipPipPipPip
  • 2,935 posts

Having the property on the magic effect would cause your objectreference to pull invalid data should the magic effect cease to exist.

No, it won't. Having the ScriptB Objectreference property in the ScriptA ActiveMagicEffect script will have no effect upon the ScriptB Objectreference script. There is no "invalid data." ScriptB won't magically lose the already-set property value when ScriptA's magic effect finishes.


Edited by Reneer, 09 November 2018 - 03:20 AM.


#7
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 7,638 posts

You can skip the property and any issues it may or may not create due to persistence, timing, etc.

 

Create a function on the object reference script that has an actor parameter and pass in the akCaster. 

Example:

Spoiler

 

But that doesn't solve the new issue of not getting any events to fire on the magic effect in question...

 

 



#8
IsharaMeradin

IsharaMeradin

    The Pale Redguard

  • Members
  • PipPipPipPipPip
  • 7,638 posts

Regarding your issue of not being able to get the caster from the magic effect due to its type.  If you can create one of those "cloak ability" spells that can reach out and fill quest aliases with targets that match the targets of the magic effect, apply a script to those aliases using the OnHit event.  Listen for the projectile from the magic effect and get the "caster" that way by using the akAgressor parameter.



#9
ReDragon2013

ReDragon2013

    Enthusiast

  • Members
  • PipPip
  • 224 posts

Myst42 wrote: "Been struggling with such thing for a while, I'm just finding out "OnEffectStart" needs to always hit something to exist"
That is impossible. Since the event "OnEffectStart" is called, it ends always with commandline "endevent".

The only way to hold alive the event "OnEffectStart" is using a while loop inside.

Myst42 wrote: "As this thing itself proves, a placed object/explosion can call scripts from the ground, but I still have no idea how to make it know who the caster of the spell that placed them was."
 

TestEffectScript

Spoiler
TestQuestScript
Spoiler

Edited by ReDragon2013, 09 November 2018 - 08:52 PM.





Page loaded in: 0.689 seconds