Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: General Battuta on May 29, 2014, 10:59:40 am

Title: Campaign persistent variables
Post by: General Battuta on May 29, 2014, 10:59:40 am
Here's a question for the coders responsible for Campaign Persistent Variables.

I have three ships: Enterprise, Falcon, and Tardis. I want to track how many of them are destroyed over the span of two missions. At the end of these two missions, I want to have a number, 0-3 inclusive, that tells me how many of them are dead.

I decide I'm going to use a CPV to achieve this. I'll call it @destroyedCount.

I add the following events to Mission 1:
If the Enterprise explodes, add 1 to @destroyedCount
If the Falcon explodes, add 1 to @destroyedCount
If the Tardis explodes, add 1 to @destroyedCount

Then I add the same events to Mission 2. If a ship blew up in Mission 1 it doesn't appear in Mission 2, so we don't need to worry about its destruction being counted twice.

In mission 3, I check the value of @destroyedCount to branch the mission into one of four states. I don't bother to handle values below 0 and above 3.

Have I implemented this correctly?
Title: Re: Campaign persistent variables
Post by: Luis Dias on May 29, 2014, 11:08:05 am
Obviously from those three, only the Enterprise is going to be destroyed, so that probably should be hardcoded.
Title: Re: Campaign persistent variables
Post by: General Battuta on May 29, 2014, 11:24:09 am
Here's a bonus round that rather spoils the game -

Spoiler:
I lose the Enterprise during Mission 1. Later in the mission, I fail, and I'm kicked to a failure debrief screen. I hit 'replay mission'. I lose the Enterprise again, but I beat the mission and proceed in the campaign. What is the value of @destroyedCount going into Mission 2?
Title: Re: Campaign persistent variables
Post by: mjn.mixael on May 29, 2014, 12:39:22 pm
I think I know what you're getting at.. and I think I've run into that same problem.

Spoiler:
@destroyedCount  becomes 2, in that case right? (Because CVs are apparently saved when the debrief starts, regardless of anything else.) When it should be 1.

I got around it by using a temporary variable and then storing a PPV upon mission success and Alt-J pressed, iirc.
Title: Re: Campaign persistent variables
Post by: General Battuta on May 29, 2014, 12:42:42 pm
I think I'd actually qualify this behavior as a straight-up bug.
Title: Re: Campaign persistent variables
Post by: mjn.mixael on May 29, 2014, 12:49:53 pm
And I would agree. CVs should take success into account, which it can get from the campaign file.
Title: Re: Campaign persistent variables
Post by: Goober5000 on May 29, 2014, 01:42:27 pm
CPVs are only supposed to be recorded when the mission succeeds and you advance in the campaign.  If you restart the mission, they are supposed to revert back to their old values as if the mission had never been played.

(I think the way this is implemented is that they are recorded when the debriefing starts, but if you select "retry the mission again later" they are rolled back.  The same happens with other player stats such as scoring and medals.)

CPVs have worked this way ever since they were implemented, lo these many years ago.  If they are acting differently in 3.7+ builds, there is probably a bug in the new pilot code.
Title: Re: Campaign persistent variables
Post by: General Battuta on May 29, 2014, 03:08:05 pm
They don't seem to be rolling back correctly after a failure debrief. This bug could be part of the new pilot code, as it dates back to the BP2 Tenebra release.
Title: Re: Campaign persistent variables
Post by: niffiwan on May 29, 2014, 05:20:17 pm
Urgh.  Another bug in the pilot code :(
Title: Re: Campaign persistent variables
Post by: Axem on May 29, 2014, 05:42:47 pm
Okay, I just wasn't sure if it was intended behavior or not. I guess it really is a bug then!

I confirmed the problem is not present in 3.6.18 and only appears with 3.7.0

I have Mantised the bug and have linked to a campaign with easy steps to reproduce.

http://scp.indiegames.us/mantis/view.php?id=3051
Title: Re: Campaign persistent variables
Post by: karajorma on May 31, 2014, 05:33:11 am
That's definitely a bug. Only player persistant variables should survive something like that without rolling back.