Script Relationships - call and set each other

Post » Mon Jun 18, 2012 3:46 am

Okay, so basically, I have 2 different scripted objects, and I want the scipt on one to be able to call functions on, and set states on, the other. The reason they need to be seperate is because I need to register events on both objects (OnActivate for one, OnItemRemoved for the other).

I can add a "ObjectReference" property to each script so that they point to each other, but is that enough? Or, even better, can I just register an event on Object B from Object A's script?
User avatar
Joie Perez
 
Posts: 3410
Joined: Fri Sep 15, 2006 3:25 pm

Post » Mon Jun 18, 2012 11:30 am

ObjectReference I believe. I think you may have to compile both scripts, then go back and set values for the relevant ones ... ?
User avatar
Josee Leach
 
Posts: 3371
Joined: Tue Dec 26, 2006 10:50 pm

Post » Mon Jun 18, 2012 4:37 am

Hm, well, I've gotten both scripts to compile without any errors, though I haven't done any in-game testing yet. One script sets another's state, let's see if I can get a function to work...

Also... What's the equivelant of "GameMode"? I'm trying to do something while the player has the alchemy menu open, and I can use "OnActivate" to determine when it's opened without much hastle, but how do I know when it's closed? Back in oblivion I could just set "int opened = 1" in the OnActivate block, then in GameMode, if "opened == 1", then it would perform the "closing menu" code.

EDIT: Calling a homemade function in Script2 from Script1 causes a compiler error, so that's a no-no...
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Mon Jun 18, 2012 8:12 am

Gamemode ... I never modded Oblivion ... but I have seen this question asked here (somewhere) more than once over the last few days ... have a search and you should find what (almost, I think) works in Skyrim/CK

I've not tried calling a function in one script from another ... but, from what I have tried, I'm not surprised you are struggling with it. That said, I sort of remember seeing something - somewhere - in the wiki to do with it (but I can't remember where .... nor if it was exactly what you want). Is Extending Scripts any use? http://www.creationkit.com/Extending_Scripts_%28Papyrus%29
User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm

Post » Mon Jun 18, 2012 9:19 am

I figured out how to call a function in script2 from script1, though it is a bit of a workaround. Basically, you put the function's code you want in an "OnBeginState" or "OnEndState" event in a state block, then you can call GoToState (from another script) to call the "function" you want. Upside, it works. Downside, no function parameters.

I'll look into a replacement for the "gamemode" issue
User avatar
Sara Johanna Scenariste
 
Posts: 3381
Joined: Tue Mar 13, 2007 8:24 pm

Post » Mon Jun 18, 2012 2:18 am

I figured out how to call a function in script2 from script1, though it is a bit of a workaround. Basically, you put the function's code you want in an "OnBeginState" or "OnEndState" event in a state block, then you can call GoToState (from another script) to call the "function" you want. Upside, it works. Downside, no function parameters.

Nice find :)
User avatar
Anthony Diaz
 
Posts: 3474
Joined: Thu Aug 09, 2007 11:24 pm

Post » Mon Jun 18, 2012 3:33 am

Found my fix for the other problem too - RegisterForSingleUpdate() in the OnActivate block, then in the OnUpdate event I put my "menu has been closed" code. OnUpdate will not happen in MenuMode.
User avatar
Darrell Fawcett
 
Posts: 3336
Joined: Tue May 22, 2007 12:16 am

Post » Mon Jun 18, 2012 12:49 pm

Another nice find (makes sense, as nothing is updated until the menuitem is chosen and/or menu closed)

... All of this sort of stuff really needs to go in the wiki, but that's a chore I've not even thought about starting ... Search in this forum is going to get very over-used ;)
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am

Post » Mon Jun 18, 2012 2:37 am

Bah, spoke too soon. After some quick testing shows OnUpdate firing in the middle of MenuMode, so I don't know what's happening there...

I might try a different animation-based approach
User avatar
Rob Smith
 
Posts: 3424
Joined: Wed Oct 03, 2007 5:30 pm

Post » Mon Jun 18, 2012 5:18 pm

That didn't work either.... I could be setting the AnimationEvent wrong, but the script seems to fire the next time I activate the table, rather than after I'm done with it like I want.
User avatar
MISS KEEP UR
 
Posts: 3384
Joined: Sat Aug 26, 2006 6:26 am


Return to V - Skyrim