On Game Load help

Post » Tue Nov 20, 2012 5:01 am

Hello,

I have an object (ship) with a constraint attached. The constraint doesn't seem to keep attached when loading a save under certain conditions. It keeps attached if I save and load the game without exiting the game, but if I exit the game after save, when loading it will not be attached.

I have set up an OnLoad() event that will reattach the constraints when the object's 3D is loaded. So, with this, if the player changes location, saves, exits the game, and returns to my object, the constraints do reattach. The same if he moves a bit away from the object, I have a function that checks for distance and reattaches the constraints. So if the player saves and loads near the object, but at a small distance, it also loads the constraints fine.

Now, the problem is mostly when the player is right by the object. I can't use the distance check, as the player is right on it and in contact. OnLoad() doesn't fire by game load, so it seems that it doesn't unload the object in the save. I could solve this by checking if the game is loaded, but there doesn't seem to be an easy way to check for this yet. Strangely, it works fine if I save and load without leaving the game, but not otherwise.

I know that SKSE was working on such an event sometime ago, but I couldn't find anything new on this.

The script is in one object and is standalone, so I would prefer not to use other scripts at any quests or any other objects. I do have the object to be constrained created by placeatme in the ship's script in the OnInit() event directly, so I could add something in that object's script though...

Any ideas how to solve this? How can I in a somewhat simple way check for game load??? If it's easier to check for saving, that could solve it too for me, as I could use a variable to check in the OnUpdate() event.

Thanks for any help...
User avatar
Ymani Hood
 
Posts: 3514
Joined: Fri Oct 26, 2007 3:22 am

Post » Tue Nov 20, 2012 7:20 am

Hopefully I'm understanding what you mean mate. If you want things to stay put, have a look at the script defaultdisablehavokonload. That script has lots of different events that stop things moving iirc. OnLoad, OnInit etc.

Have a look at the mate.
User avatar
Hazel Sian ogden
 
Posts: 3425
Joined: Tue Jul 04, 2006 7:10 am

Post » Tue Nov 20, 2012 2:23 am

Thanks for the suggestion. I had completely forgotten about that script. I checked it and it won't work for my purpose, as I'm enabling and disabling havok often during the game, and it works as intended how I have it setup. I think that script just checks for when the object is loaded the first time, but not on save load. I did find in there the Is3DLoaded() function, which I had forgotten about. I might use it for something, although OnLoad is working fine, except when the player is on board the ship.

My ship is havoked. I disable havok when the player is away, but if he saves or loads while sailing, I have no way to check for that and prepare the ship for a later load, which would involve disabling the havok again and reattaching the constraints, which seem to get lost on game exit.
User avatar
Hannah Whitlock
 
Posts: 3485
Joined: Sat Oct 07, 2006 12:21 am

Post » Mon Nov 19, 2012 11:35 pm

Ah ok mate :) hopefully you sort it, or someone else has another idea :)
User avatar
Dina Boudreau
 
Posts: 3410
Joined: Thu Jan 04, 2007 10:59 pm

Post » Tue Nov 20, 2012 2:34 pm

I could solve this by checking if the game is loaded, but there doesn't seem to be an easy way to check for this yet.

http://www.creationkit.com/OnPlayerLoadGame_-_Actor is what you'd want for this.
User avatar
Mimi BC
 
Posts: 3282
Joined: Sat Oct 07, 2006 10:30 pm

Post » Tue Nov 20, 2012 2:26 am

That event can't be called in an ObjectReference script, right? So for that one to work, I would need a quest just for this purpose, add the player reference as an alias, and attach a script to the alias with the event. Then, on game load, the event would call a function inside my ship script, which would do it's stuff. Am I understanding this right? I had hoped not to touch the player though, but I guess this might actually be the only solution.
User avatar
Haley Merkley
 
Posts: 3356
Joined: Sat Jan 13, 2007 12:53 pm

Post » Tue Nov 20, 2012 7:05 am

That event can't be called in an ObjectReference script, right? So for that one to work, I would need a quest just for this purpose, add the player reference as an alias, and attach a script to the alias with the event. Then, on game load, the event would call a function inside my ship script, which would do it's stuff. Am I understanding this right? I had hoped not to touch the player though, but I guess this might actually be the only solution.
Exactly. But none of this involves modifying the player's actor or its script.
User avatar
Luis Longoria
 
Posts: 3323
Joined: Fri Sep 07, 2007 1:21 am

Post » Tue Nov 20, 2012 2:04 pm

Ok, I have a very stupid problem now. :blush: I actually never called a function from outside it's own script, and I think I'm not understanding the wiki...

My function is inside a script from an activator which is placed in the world through the editor. It looks like this:
Spoiler
Function GameLoaded ()	AttachConstraints()	Debug.Notification(ConstraintStatus)	Speed = 0	StopHavok()EndFunction

I tried calling it from the player alias script like this:
Spoiler
Scriptname AADXPlayerAlias   Event OnPlayerLoadGame()	AADXLongBoatMainScript.GameLoaded()EndEvent
Compiler Error: cannot call the member function GameLoaded alone or on a type, must call it on a variable

And also like this:
Spoiler
Scriptname AADXPlayerAlias   Activator Property AADXLongBoat  Auto  Event OnPlayerLoadGame()	AADXLongBoat.GameLoaded()EndEvent
Compiler Error: GameLoaded is not a function or does not exist

What am I doing horribly wrong?
User avatar
TWITTER.COM
 
Posts: 3355
Joined: Tue Nov 27, 2007 3:15 pm

Post » Tue Nov 20, 2012 4:00 am

"AADXLongBoat.GameLoaded()" would work if AADXLongBoat was a global function but since it is not you need an instance of AADXLongBoat. And the compiler cannot figure itself whether AADXLongBoat script is attached to zero, one or thousand activators.

So declare a property of this type on the alias and assign it in the Creation Kit.
User avatar
Gisela Amaya
 
Posts: 3424
Joined: Tue Oct 23, 2007 4:29 pm

Post » Tue Nov 20, 2012 4:13 am

So, if I understand correctly.

1. The property would have to point to the exact reference where the function needs to be called?

2. Or would be enough to place a placeholder in the world and point it to that, sink it under the ground, and then it would work with all objects?

If it's the first, then it's a real pitty, as my ships can at the moment be spawned directly in game and will work out of the box. This wouldn't be possible then. With the second, it would still be possible.

Anyway. I will test around. Thanks for the help!
User avatar
Sophie Morrell
 
Posts: 3364
Joined: Sat Aug 12, 2006 11:13 am

Post » Tue Nov 20, 2012 7:11 am

if GameLoaded() only modifies global variables and such, you can pass any reference. Otherwise, GameLoaded likely has to be ran on a specific reference and then you must provide this one. The solution in this case is to register your reference on the quest at the time it is created (create a property theActivator on the quest, a theQuest on the activator, and when the activator is created make it call theQuest.theActivator = self).
User avatar
Dean Brown
 
Posts: 3472
Joined: Fri Aug 31, 2007 10:17 pm

Post » Tue Nov 20, 2012 8:50 am

I did really want to keep my ships spawnable as long as possible, so what I ended doing is this with a global variable:
Spoiler
Scriptname AADXPlayerAlias extends AliasGlobalVariable Property AADXGameLoadGlobal  AutoEVENT OnPlayerLoadGame()	AADXGameLoadGlobal.SetValue(1)	RegisterForSingleUpdate(3)EndEVENTEVENT OnUpdate()	AADXGameLoadGlobal.SetValue(0)EndEVENT

This gives my ship enough time to detect that the game was loaded and do whatever. It works well.

Thank you all for your help!
User avatar
Rude Gurl
 
Posts: 3425
Joined: Wed Aug 08, 2007 9:17 am


Return to V - Skyrim