Home   Help Search Login Register  

Author Topic: Savegames and why they affect triggers and scripts  (Read 2568 times)

0 Members and 1 Guest are viewing this topic.

Offline Wiggum

  • Members
  • *
Savegames and why they affect triggers and scripts
« on: 06 Sep 2010, 21:09:39 »
Hi,

im currently totally helpless with my problem...


My problem:

Ingame i have a trigger with Condition time > 1 and OnAct nul = execVM "random_music.sqf".
Code: [Select]
//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...

I got told that the game thinks the trigger/scipt is already activated in some way.
But i tried many different combinations and it still not works after a reload...

Can you help ?

See also:
http://dev-heaven.net/issues/12734
« Last Edit: 06 Sep 2010, 21:14:10 by Wiggum »

Offline SaOk

  • Missions Depot Staff
  • *****
    • My youtube profile
Re: Savegames and why they affect triggers and scripts
« Reply #1 on: 06 Sep 2010, 23:17:23 »
I think the "time" may only get to zero when the whole mission is restarted, not loaded from savegame. Have you tried to check the time via hint after loading the game?
Code: [Select]
hint format ["%1",time];
« Last Edit: 06 Sep 2010, 23:21:31 by SaOk »

Offline Wiggum

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #2 on: 07 Sep 2010, 19:15:32 »
Thanks, but this does not work.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Savegames and why they affect triggers and scripts
« Reply #3 on: 07 Sep 2010, 20:42:42 »
At least in OA time does not reset to zero after loading a saved game anymore.

So I guess you need to monitor time and if it suddenly goes back to earlier time it means a game was loaded.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: Savegames and why they affect triggers and scripts
« Reply #4 on: 07 Sep 2010, 20:53:42 »
I'm not at all familiar with Arma editing, but based on my knowledge of OFP scripting it strikes me that if time > 1 is the only condition of the trigger - and it's set to activate repeatedly - it will activate at 1.0001 seconds, 1.0002 seconds, 1.0003 seconds, 1.0004 seconds and so on until either you quit the mission or your PC crashes.

Besides which, should it not be this && time > 1?

From the OP I'm assuming that the effect being sought is continuously playing randomly selected music, regardless of saving and coming back to the mission. You'll likely need a global variable for this.

Initialise WIGG_musicvar as true in the init file - Arma2 still uses an init file right?  :dunno:

Trigger condition becomes
Code: [Select]
this && time > 0 && WIGG_musicvar
Code: (random_music.sqf) [Select]
// random_music.sqf

// deactivate the music variable for now
WIGG_musicvar = false;

// create an array of possible music scripts
_scripts = ["music.sqf", "music2.sqf", "music3.sqf"];

// run one of the scripts at random
[] execVM (_scripts select (floor random count _scripts));

// hint something so we know this has run
hint "test";

// wait an appropriate length of time - however long the music lasts
whatever the arma2 code for waiting is...

// then set the global variable to true again
WIGG_musicvar = true;

Now even if the mission is saved then reloaded, the global variable will definitely be remembered by the engine, and once it's set to true the trigger - if repeating - will activate the script again and again and again, but in a controlled way.

Untested, but see how it goes.  :good:

Offline Wiggum

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #5 on: 07 Sep 2010, 21:46:11 »
Thanks bedges, but this does not work.

@ h-
Very interesting...any idea how to monitore time ?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Savegames and why they affect triggers and scripts
« Reply #6 on: 08 Sep 2010, 18:39:47 »
My idea was pretty much the same as the one bedges suggested, just with a different approach.

But unfortunately neither works (as far as I can tell) as everything is saved correctly nowadays so you can't abuse any commands like you used to do with time.
And a repeated trigger will not fire again when a saved game is loaded because it has already triggered and that state has been saved in the savegame..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline ZapBrannigan

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #7 on: 09 Sep 2010, 07:56:49 »
I have  a similar problem in my mission. When the player saves the game the light  i placed with
Quote
light1 = "#lightpoint" createVehicle getpos lightspot1
light1 setLightBrightness 0.05
light1 setLightAmbient[1.0, 1.0, 1.0]
light1 setLightColor[1.0, 1.0, 1.0]
light1 lightAttachObject [lightspot1, [0,0,4]]
exit
will turn off when he loads the game,
and some titletexts in another script will either not show up or show up very quickly and then disapear and be unreadable.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Savegames and why they affect triggers and scripts
« Reply #8 on: 09 Sep 2010, 16:10:13 »
Quote
When the player saves the game the light  i placed
I tested (with OA beta build 73116, they apparently released a newer one today though) and at least the created lightpoint stays "alive" after reload so I guess BIS have fixed the lightpoint not getting saved but forgot to add the light parameters into the mix.

So you are also screwed I guess. Earlier you could prevent your problem happening by having a script monitor whether the lightpoint exists or not and if not re-create it.
Same could have been used as a workaround for Wiggum's problem but no more.
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Wiggum

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #9 on: 11 Sep 2010, 09:10:57 »
I found a very interesting script inside the EW Campaign !

Code: [Select]
/*
File: saveload.sqf
Author: Karel Moricky

Description:
Save/Load Manager v3.0

Parameter(s):
_this: code executed after load
*/

while {true} do {
880224 cutrsc ["saveload","plain"];

//--- Resource is null - game loaded
waituntil {isnull (uinamespace getvariable "str_saveload")};

//--- Mission specific code
[] spawn _this;
};

Can someone explain what this script does exactly ?
I had some problems with scripts that does not load after save/reload...maybe this script can be a solution !

Why else would they call it "Save/Load Manager v3.0"... ?


Thats whats from a init.sqf of the EW campaign:
Code: [Select]
//--- Save/Load manager
{
startLoadingScreen ["EW","RscDisplayLoadMission"];

if (DirectorsCut) then {
if !(RAH1 getvariable "str_bay") then {[RAH1] spawn str_ew_closebay};
};

//--- No weapons
if (count weapons rah1 == 0) then {5 cutrsc ["nofire","plain"];};

//--- enablesimulation command is reset after load
/*
nukeboy enablesimulation false;

if ((position rah1 select 0) >= 7070) then {
helipatrol enablesimulation false;
};
if  (isnil "suCount") then {
{_x enablesimulation false} foreach [su1,su2,su3,mi1];
};
if (isnil "artystrike") then {icarus enablesimulation false};
{_x enablesimulation false} foreach units tu1;
*/

if (DirectorsCut) then {};

endloadingscreen;
} spawn bis_ew_fnc_saveload;


Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Savegames and why they affect triggers and scripts
« Reply #10 on: 11 Sep 2010, 10:57:32 »
It appears to create a custom Rsc which sets a variable in the uiNameSpace and if it gets nulled the game is loaded.

Interesting thing, you just need to put that custom resource in your description.ext:
Code: [Select]
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
Code: [Select]
//random_music.sqf
scripts=["music.sqf","music2.sqf","music3.sqf"];
_select = (scripts select (floor random count scripts));
[] execVM _select;

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

        [] execVM _select;
};

Didn't test with your script, had my own which I used so no 100% guarantees yours works..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Wiggum

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #11 on: 11 Sep 2010, 11:15:34 »
Thanks h- !  :good:

This is it...now the music plays again after a reload !

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Savegames and why they affect triggers and scripts
« Reply #12 on: 11 Sep 2010, 16:00:15 »
Thanks.
But as it usually is someone points out a very obvious and better solution.  ::)

What UNN suggested at your BIF topic is better in a way that you don't need any description.ext hassles, so it's simplier:

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

_origTime = diag_tickTime;
while {alive player} do {
sleep 1;
if (((_origTime+5)<diag_tickTime) || (diag_tickTime<_origTime)) then {[] execVM _select; _origTime = diag_tickTime}
else {_origTime = diag_tickTime};
};
This code (and the one I suggested earlier) has one flaw though, the code makes the music play always when a game is loaded after that script has been started even if the music itself has stopped playing ages ago. Which might not be a wanted feature so adding some sort of timer into the mix might counter act that one:

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

_origTime = diag_tickTime;
while {alive player || time>=300} do {
sleep 1;
if (((_origTime+5)<diag_tickTime) || (diag_tickTime<_origTime)) then {[] execVM _select; _origTime = diag_tickTime}
else {_origTime = diag_tickTime};
};
That should exit the script once 5 minutes has passed since the script was started. In other words if the player saves 5 minutes after the script has been started and reloads the music no longer starts playing.
« Last Edit: 11 Sep 2010, 16:06:11 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Wiggum

  • Members
  • *
Re: Savegames and why they affect triggers and scripts
« Reply #13 on: 11 Sep 2010, 16:28:04 »
Thanks for pointing that out h- !  :good: