Jump to content

Communication between scripts and inside a script


Dryess

Recommended Posts

Hi everyone,

 

I'm having 2 pretty simple (I think the answers are quite simple) problems but I can't seem to wrap my mind around the solutions

 

1) I wanna have a very simple script effect that you cannot re-launch until it has been completed (if the script is already running than just do nothing)

So i did this :

Scriptname DashScript extends ActiveMagicEffect

Bool Property canUse =false Auto

Event OnInit()
	canUse=true
EndEvent

Event OnEffectStart(Actor akTarget, Actor akCaster)
     #...SOMETHING...#
	If( canUse )
		canUse =False
		#...SOMETHING...#
		canUse =True
	EndIf
EndEvent

For me what should happend:

- OnInit() is only launched once so that canUse will only be true the first time

- If I launch it once it turns canUse to False until it has completed its task then back to True

- If try launching a 2nd time while the other is active it shouldn't do anything

 

But at runtime I can chain-launch it without it being completed

 

Maybe OnInit is called severall times and not just one ?

 

I tried using only a variable and not a property (I used a property the first time because I'm not sure how to pass a Boolean or Int property to another script and I though as I might need it in some other script I might as well put it directly as a Property)

 

->(Q1)So how do I do that the simple way ( without applying a useless Spell to act as a bool for example, as I've seen it being done sometimes) ?

 

 

 

 

2) On a completely unrelated object

 

I have an other "ingestible" (=skyrim potion) kind of item that does (I based it on Bullet Time - Slow Time by registrator2000 , and I'm trying to implement a deactivable invisibility mod by simplifying his process ) and ended up with this :

1st time you use it to activate the effect :
 Item=> (MagicEffect) Controller => (Spell) MainEffectsLauncher    |=>(MagicEffect) MainEffect
                                                  |                |=> (MagicEffect)AutomaticDispel if actionpoints are bellow 1.0                 
                                                  |  
                                                  | => (Spell) APDrain

2nd time ( if no AutomaticDispel  before) to deactivate
Item=> (MagicEffect) Controller ( checks if  MainEffectsLauncher is present and if so removes both spells)

The MainEffectsLauncher Spell is used here as a substitue for my problem earlier in (1) and as registrator2000 was using it I kept it this way, even though i'd want to get rid of it, if possible ...

 

 

-> (Q2.a) Is there a way to launch MagicEffects on an Actor directly from a script without using an intermediate like a spell ?

 

 

 

 

 

 

From the AutomaticDispel script I'd want to use a function from Controller (not a global one) to do that I've tried :

Scriptname AutomaticDispel extends ActiveMagicEffect

ScriptObject Property   LinkToDispell  Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	#...SOMETHING...#
	(LinkToDispell as Controller ).EndCloakEffect() ; the function i'd want to call
	#...SOMETHING...#
EndEvent

(Controller also inherits from ActiveMagicEffect who is a child of ScriptObject )

The compiler is fine with that but I can't seem to be able to link the ScriptObject Property with Controller within the Property manager, it just does not offer me this option : when I hit "Edit value" the "Pick Object" field only offers me NONE as an option...

I'm assuming this comes from the fact that the ScriptObject template has the keyword Hidden in it's definition, so :

 

->(Q2.b) How do I link my LinkToDispell Property with the actual Controller script ( I've tried to change it's type from ScriptObject to Controller but as its value is still <<Default: None>> it doesn't do anything ingame ) ? or How to call functions from an other script more generally if my way won't work ?

 

 

 

Any help would be gratly appreciated !

Edited by Dryess
Link to comment
Share on other sites

Before reading on I just want to point out that I do not have the CK or the game on PC and can hence not verify that any of what I write actually works. However, based on all I've read and my understanding so far, this should work or at least be a nudge in the right direction. All I can do is read code and have no idea of the layout of the CK and changing stuff there. So, to continue.

 

To your first question the answer is very simple: States. You code would simply become:

Scriptname DashScript extends ActiveMagicEffect

State Waiting Auto ; auto tells it to start in this state
  Event OnEffectStart(Actor akTarget, Actor akCaster)
    GoToState("Busy") ; sets the script to busy state, but the rest of the event will continue to run
    #...SOMETHING...#
    GoToState("Waiting") ; we're done so we can once again be used
  EndEvent
EndState

State Busy
  Event OnEffectStart(Actor akTarget, Actor akCaster)
    ; leave this empty as we don't want it to do anything if we're in this state
  EndEvent
EndState

I think you're original script would work, but the error was that you can't declare properties in script like this: "Bool Property canUse =false Auto". You should have either declared the property false in the CK, or have used a variable since you're script isn't a Const.

Edit: You should be able to declare auto properties like that, sorry.

Either way, states are the way to go.

 

 

As for your second question, I'm not sure I completely understand what you're trying to do due to my limited understanding of the CK. But I don't think you can get way from using spells. Those are the only things (from what I've gathered) that can apply MagicEffects. But you can use AddSpell on any actor you wish to apply it to, as well as DispelSpell to remove it's effects.

 

If if you want the LinkToDispell to be a Controller property, you should just define it as such and I think it will show up in the menus correctly: "Controller Property LinkToDispell Auto". I am assuming that you have another script named "Controller". Then just calling it as "LinkToDispell.EndCloakEffect()" should be enough.

 

Otherwise, the way to call functions on remote scripts is through the use of CallFunction. The wiki entry is pretty self explanatory, but this shouldn't be needed in your case.

 

 

I hope this has helped you somewhat, but I am limited in my situation not having access to the CK.

Edited by timtimman
Link to comment
Share on other sites

Thank you very much for all this !

 

I will try verything when I get time, but just for the

 

 

If if you want the LinkToDispell to be a Controller property, you should just define it as such and I think it will show up in the menus correctly: "Controller Property LinkToDispell Auto". I am assuming that you have another script named "Controller". Then just calling it as "LinkToDispell.EndCloakEffect()" should be enough.

My problem is that the property manager doesn't ALLOW me to select it, whenever I want to get a ScriptOject or a particualr script (that inherits from it) all it offers me is a list containing none (the type si recognized but it won't allow me to select my script):

( The true name of COntroller is CloakingScript )

 

http://i.imgur.com/jGsiJhz.jpg

Link to comment
Share on other sites

From the looks of it (not familiar with the CK), it might be that it's defined as Const, which might not let you do that. Or you've written it in the wrong order.

 

As far as I know it should be written as: CloakingScript Property CloakControllerLink Auto Const ?

 

Or maybe it's just the CK failing it's inheritance.

 

If it's just pure ScriptObject inheritance all the way, you wouldn't be able to pick an object (I think). Try an ObjectReference as property, and the item should have the CloakingScript attached to it. Then you should be able to use myRef.EndCloakEffect() or maybe (myRef as CloakingScript).EndCloakEffect().

 

I could be wrong, but hope it helps.

Link to comment
Share on other sites

Don't worry I've tried with const and without it, it doesn't change anything ;)

So yeah it seems to me that it's the inheritance from Scriptobject that's stopping me

As for the order, don't worry it'es the CK layout, if you look at the top of the columns, it does correspond to what your saying, with good type and such ...

 

I'm quite puzzled : why would ObjectReference get this script ? The script extends ActiveMagicEffect which comes directly from ScriptObject, so how would it get a hold on this script , by the fact that an object launches a magic effect that itself has this script attached ? That seems far fetched ( i'm not saying it might not be the case, just seems odd to me :/ )

I can't run the test tonight but I'll be sure to check it out thanks ;)

Link to comment
Share on other sites

Sorry, I'm phrasing was a bit off. I don't think ObjectReference would get a hold of that script. As you pointed out, that would be very weird.

 

But you could perhaps get hold of it and use it in script, by the means of setting the object which has the CloakingScript on it: ObjectReference Property ObjectWhichHasScript Auto. And maybe using that, (since you need a reference) casting it as a CloakingScript: (ObjectWhichHasScript as CloakingScript).

 

 

I assume you've check your spelling, so it isn't an annoying mistake like that.. Both name of the file and name said in the file. Cloaking and Claoking might be a simple typo to make.

 

Right now otherwise, I'm out of ideas. Hope some of them has been helpful at least.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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