Jump to content
wiggum2

Scripts dont work after save/reload

Recommended Posts

Hi,

today i run into two big problems with scripts that dont work after a reload of a savegame...

The problem is pretty much unknown i think, thats kind of strange because it can really break Missions !

For example my current problem:

Ingame i have a trigger with Condition time > 1 and OnAct nul = execVM "random_music.sqf".

//random_music.sqf
scripts=["music.sqf","music2.sqf","music3.sqf"];
_select = (scripts select (floor random count scripts));
[] execVM _select;
hint "test";

Now, if i start the mission i hear music and get the hint.

Then i save the game and reload...and now there is no music and no hint !

But why ?

time > 1 should fire again after reload and i also tried it with alive player and it still does not work...

Come on guys, dont tell me no one else have ever run into such problems with save/reload and scripts that dont want to work.

The funny thing is that some scripts work and some not, i dont know why...please help me if you know more !

See also:

http://dev-heaven.net/issues/12734

Edited by Wiggum

Share this post


Link to post
Share on other sites

The challenge with the trigger is that it has already been activated when you go to reload, therefore it has no reason to trigger again. It's easy to see this if you output the results of the 'triggerActivated' command against your trigger (such as with a radio call or addAction), save and reload, and view the output again on the trigger. It will show activated still, which means the state of the trigger was saved correctly. You really don't want all of your activated triggers to go off again, hilarity would ensue. So the trick is figuring out how to get the music playing again. I looked for some sort of event handler when the mission is loaded from a save, but I don't see that. init.sqf only runs when the mission is started from scratch, so sorry not really help to get you going. Hopefully someone knows a trick for this.

Share this post


Link to post
Share on other sites

Ok, i understand that.

But like you said, there must be some workaround for this Problem !

Please help if you know more !

Share this post


Link to post
Share on other sites

I'm at a loss as to a workaround. I had never considered this problem before, and now I too would like a resolution :D

Share this post


Link to post
Share on other sites

Shot in the dark here but what if you use variable/script handle instead of just nul ?

RandomMusic = execVM "random_music.sqf"

Savegame should save content/state of variables.(?)

Edit: I should have read your post more carefully. You want to relaunch the script after load so this won't make any difference.

Edited by Coyota

Share this post


Link to post
Share on other sites

It looks like there is no way to fiy this problem...sad but (maybe) true... :(

Share this post


Link to post
Share on other sites

Set trigger to repeat?

Edited by ziiip

Share this post


Link to post
Share on other sites

Unfortunately that does not seem to work, because the trigger has to enter a deactivated state before it will repeat. At least when the activation is based on time, it has no reason to deactivate. The only idea I have is to use a custom save (like with a radio trigger) that saves a variable along with the mission, so that when you reload it triggers a repeat trigger that activates based on that var. The downside is that you'd have to rely on the player using this custom save.

Share this post


Link to post
Share on other sites

Someone else wrote that in OA time is no longer reset too zero after load of mission !

I really not understand why there is no command that detects if a savegame was just loaded...

I i really would like to know why this savegame problem not breaks the BIS missions too...

Share this post


Link to post
Share on other sites

Honestly I dont see any reason why you would use the

time > 1
condition in your trigger. Why dont you just place a soldier somewhere far from battlefield and put a trigger over him that detects if he is there. Give the soldier a wayponint outside the trigger zone. That way the trigger will deactivate and music will play every time you restart the mission.

I dont even understand why you have this problem since restarting the mission resets everything.

Edited by ziiip

Share this post


Link to post
Share on other sites

The problem is not restarting the mission, it is from loading a saved game, which maintains the state you had when it was saved. However a few things don't automatically restore, like music that was playing.

About the time, I did verify that a couple days ago. The time value picks up where it left off at save. Is there a way to detect if music is playing or not?

Share this post


Link to post
Share on other sites

I understand AZCoder, but judging from the trigger condition, he obviously want the music to start right as the missin launches.

Edit: oh man im such a retard sometimes.:butbut:

Edited by ziiip

Share this post


Link to post
Share on other sites

The music does start at mission launch, that's not the problem. It is load from save where it won't start. I think from his last post, he was epecting time to reset itself when loading a save, but that's not the case.

Edited by AZCoder
clarification

Share this post


Link to post
Share on other sites
Unfortunately that does not seem to work, because the trigger has to enter a deactivated state before it will repeat. At least when the activation is based on time, it has no reason to deactivate. The only idea I have is to use a custom save (like with a radio trigger) that saves a variable along with the mission, so that when you reload it triggers a repeat trigger that activates based on that var. The downside is that you'd have to rely on the player using this custom save.

I was going to post something like this a couple of days ago. ... To put an autosave at places in a script, or in triggers. Then you could restart from that. However, I realized, after a complete game shutdown and resume, well, that is exactly what you would have to do, resume. To revert (after a shut down), you would have to resume, then revert. Not very elegant. Saving and reverting in-game, though, that could work.

BTW, is this mission just for you? No insult intended, to each his own, but if 'I', me, just me, were to DL a mission where the author forced me to listen to 3 tracks everytime I restarted from a save or revert. I would delete the thing immediately, and never touch it again. And, I would be leary of any other work from that author. Again, just me, and how I feel.

Also, I do not 'see' how the save game option, "can really break Missions". It appears to me it is doing exactly what it is suppose to do... saving the game in the state that you left/saved it.

Anyway, sorry I do not have more for you than the first idea.

Share this post


Link to post
Share on other sites

I do agree that the mechanism works as it's supposed to. I was mostly curious if there was an event handler for loading from a save.

I tested the Jukebox module with OA that randomly plays tracks. And guess what? If you load a saved game, the jukebox won't play music again, at least it did not for me after waiting about 20 seconds.

Wiggum: I do have one possible solution. Create a script, and call it with execVM, and do something roughly like this:

sleep 1;
while { time > 0 } do
{
      // CALL Random Music Script Here
sleep (random(60) + 300);
};

Make sure to have the sleep 1; before the while-loop or it won't execute. The state of this thread gets saved with the mission, so when you reload, the thread keeps running. When you load from a save, the last sleep command will still run, so music won't start until that's done. I know it's not continuous music, but music will kick off again at some point at least.

Share this post


Link to post
Share on other sites

Well, I have done some research, but I do not find anything.

Can we be clear on something, though? You want the music playing for the whole time you are in the mission? Or, is it just 3 tacks each time you start/restart that you want?

EDIT: If this is for continuous... I got tracks to repeat using a move and cycle waypoint, and they were still playing on revert and resume, but you have to time it, also. In that case, I was using a unit running back and forth. I checked his distance running to when the track stopped, cut it in half, then had him run to a cycle waypoint. Crude, yes, but was just to test if it would restart the music track, and restart it after resume. It did. So, that's an idea to work from.

I don't ssee why you could not do the same with triggers. Both triggers activating a music sqf, and having your sqf setup with an if statement (or whatever) so if one sqf was playing it would not play, or have it setup to waitUntil the playing is finished, and start another sqf, etc. That's still pretty crude, but hey... ! :)

How about two triggers over the whole map that do as described above, activated by Anyone. ?

I think you already could get the triggers to work, but the waypoints did work! Sooo, maybe scripted waypoints?

Edited by CyOp

Share this post


Link to post
Share on other sites

This is what I use for saved games in the RKSL System:

Launched at mission start:

//Start the save restore script
if !IsMultiplayer then {_pScript=[] ExecVM "\rksl\rksl-system\s\RKSLSaveRestore.sqs"};

RKSLSaveRestore.sqs:

//Get the dialog time
_mytime=diag_tickTime;

waitUntil
{
//Give it a tolerance of five seconds to check for time differenct
//If the saved dialog time+ is less than the current dialog time
//Or the current dialog time is less than the saved dialig time
//Then we have restored a saved game so fire off the event handler
if (((_mytime+5)<diag_tickTime) Or (diag_tickTime < _mytime)) then
	{
	//reset the saved dialog time to the current one
	_mytime=diag_tickTime;

	//Wait for the game display to be created
	waitUntil {!(isNull (FindDisplay 46))};

	//Call the save restore event
	{Call ((RKSL_SYSTEM Select RKSL_SYSEVENTSINDEXED) Select _x)} ForEach (RKSL_SYSTEM Select RKSL_SYSEVENTSRESTORE);
	}
	else
	{
	//Update the current dialog time
	_mytime=diag_tickTime;
	};

//Repeat for ever
false
};

This bit:

//Call the save restore event
{Call ((RKSL_SYSTEM Select RKSL_SYSEVENTSINDEXED) Select _x)} ForEach (RKSL_SYSTEM Select RKSL_SYSEVENTSRESTORE);

Can be replaced with whatever you want to restart due to a restore.

I did see another method kicking about the forums that looks a bit better, but in the mean time this works fine.

Share this post


Link to post
Share on other sites

h- from the OFPEC forum has found a way to solve this problem !

Put that custom resource in your description.ext:

class RscTitles
{
   class saveload
   {
       name = "Save/Load";
       duration = 10e10;
       fadein = 0;
       idd = -1;
       movingEnable = false;
       onload = "uinamespace setvariable ['str_saveload',_this select 0];";
       class controls    {};
   };
};

And in your script:

//random_music.sqf
[color="Blue"]scripts=["music.sqf","music2.sqf","music3.sqf"];
_select = (scripts select (floor random count scripts));
[] execVM _select;[/color]

[color="Red"]while {alive player} do {
880224 cutrsc ["saveload","plain"];
waituntil {isnull (uinamespace getvariable "str_saveload")};

       [] execVM _select;
};[/color]

Remember, that red marked stuff is the important part !

Replace the blue marked stuff with anything you like.

@ UNN

Thanks but this does not work for me...( and yes, i changed it to .sqf ;) )

Share this post


Link to post
Share on other sites

UNN - thanks for posting, I had not seen diag_ticktime, I was looking for another time counter. Cool.

Wiggum - glad you found a solution that works for you, may take me some time to understand how it works, thanks for sharing.

Share this post


Link to post
Share on other sites

Wiggum - glad you found a solution that works for you, may take me some time to understand how it works, thanks for sharing.

...hey, this is so easy and should work for everybody !

Use this script:

//saveload_manager.sqf
[color="Red"]while {alive player} do {
880224 cutrsc ["saveload","plain"];
waituntil {isnull (uinamespace getvariable "str_saveload")};[/color]

[color="Blue"]        nul = execVM "myscript.sqf";
       nul = execVM "myscript.sqf";[/color]
[color="Red"]}[/color]

Start this script in your init.sqf and put the scripts that should execute after a reload into the blue marked area (like i did it with nul = execVM "myscript.sqf";) and it should work !

Ah, and dont forget to put that custom resource in your description.ext !

Share this post


Link to post
Share on other sites
h- from the OFPEC forum has found a way to solve this problem !

Worth mentioning obviously is that I didn't come up with that, it's BIS doing from the EW campaign (which you pointed me to) so no praise for me on that one :p

@UNN

Meh, diag_tickTime never even crossed my mind :icon_ohmygod:

Share this post


Link to post
Share on other sites
h- from the

@ UNN

Thanks but this does not work for me

Works fine for me in Arma2 and OA. For anyone interested you can try for yourself Save Load Test

( and yes, i changed it to .sqf ;)

btw doesn't matter what you called your file:

[] execVM "tomato.juice";

Will run fine, remember execVM automatically expects the content of the file to be in sqf format :)

The only time the extension actually means anything, is with the addaction command or similar.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×