Page 1 of 1

Saving info for later missions

PostPosted: 27 Aug 2015, 18:50
by The Dark Lord
Since we will probably never have siege weapons in the Remake (a little part of me dies now that I admit it :'( ) and TNL will never be as epic as it could have been, I have to replace a mission that is all about these machines. It is mission 14 (out of 16), and I was thinking to make it some 'sneak mission' where the player can choose to infiltrate a specific base for a (variety of) reward(s) in the final mission. However, I would need to translate the player's choice into information which needs to be stored until the start of mission 16. Is that possible? I knew there was some discussion about it, but if I remember correctly nothing came out of it (which is a shame :P).

Re: Saving info for later missions

PostPosted: 27 Aug 2015, 18:58
by Krom
This is possible in KaM Remake dynamic scripts in r6720. You need to use some special record which is carried over to next missions scripts iirc.
Please see https://github.com/Kromster80/kam_remak ... paign-data

Lewin may add more details.

Re: Saving info for later missions

PostPosted: 27 Aug 2015, 19:02
by Strangelove
This looks pretty interesting. My brain is already working on a possible usage-scenario. :D

Re: Saving info for later missions

PostPosted: 27 Aug 2015, 20:39
by The Dark Lord
This is possible in KaM Remake dynamic scripts in r6720. You need to use some special record which is carried over to next missions scripts iirc.
Please see https://github.com/Kromster80/kam_remak ... paign-data

Lewin may add more details.
Ah, that is splendid news. :) When the moment is there I will try it. First I have to finish mission 10 and 13. :)

Re: Saving info for later missions

PostPosted: 07 Sep 2015, 14:54
by Strangelove
This is all nice and good, but i've played around with this stuff a few hours now and it still doesnt work at all. Can somebody please provide a valid example on how to use that?

Re: Saving info for later missions

PostPosted: 07 Sep 2015, 16:45
by Krom
IIRC newer campaigns in KMR r6720 used that.

Re: Saving info for later missions

PostPosted: 07 Sep 2015, 17:11
by Strangelove
IIRC newer campaigns in KMR r6720 used that.
I couldnt find the file in any of campaigns that come with r6720. Which campaign exactly uses this feature?
Funniely enough it sometimes works, but when i try to use more than 1 array the map crashes after it finished loading. Maybe I am doing something wrong, but like i said, i wasn't able to find any documentation (beside the one that you linked) or other use-case of this feature.

Re: Saving info for later missions

PostPosted: 07 Sep 2015, 17:23
by Krom
I'm sure someone tested it when we have implemented that. Maybe Lewin can shed some light on this.

Re: Saving info for later missions

PostPosted: 07 Sep 2015, 17:34
by Strangelove
I'm sure someone tested it when we have implemented that. Maybe Lewin can shed some light on this.
Thanks for your response again. I will try some stuff again and see if i can get it to work. I will post my attempts later on. Maybe you guys have some feedback.
Also, do you have any plans to extend the possibilities of this feature? Like supporting types for example.

Re: Saving info for later missions

PostPosted: 08 Sep 2015, 07:36
by dicsoupcan
I'm sure someone tested it when we have implemented that. Maybe Lewin can shed some light on this.
i had it planned for future missions, but as far as i know no campaign ever implemented this yet. i had a few pm's to and form lewin about this, but i cannot find it atm.

Re: Saving info for later missions

PostPosted: 08 Sep 2015, 07:56
by Strangelove
I'm sure someone tested it when we have implemented that. Maybe Lewin can shed some light on this.
i had it planned for future missions, but as far as i know no campaign ever implemented this yet. i had a few pm's to and form lewin about this, but i cannot find it atm.
Thanks for checking. I am playing around with it just now and it seems to work with single varibales, but as soon as i try to use arrays, i get error messages ingame or the map crashes just before its done loading.
Maybe I am just handling the arrays wrong? I ve already started to doubt myself lol.

Only the fallowing seems to work:
  Code:
procedure OnPlayerVictory(aIndex: Integer); begin CampaignData.Mission1.RemainingUnits := 30; end;
  Code:
record Mission1: record RemainingUnits: Integer; end; end;
When i do it as this, i get a crash while loading the map: (sometimes...)
  Code:
var aHouse: array of Integer; procedure OnPlayerVictory(aIndex: Integer); var H: Integer; begin aHouse := States.PlayerGetAllHouses(1); for H := 0 to Length(aHouse)-1 do begin CampaignData.Mission1.iType[H] := 1; end; end;
  Code:
record Mission1: record iType: array of Integer; end; end;
Image

EDIT: Finally figured it out. I had i right a lot of times already it seems. Problem is that whenever you change pretty much anything, you have to close KaM and delete the Campaigns.dat-File in the Save-Folder...

Re: Saving info for later missions

PostPosted: 08 Sep 2015, 22:54
by Lewin
EDIT: Finally figured it out. I had i right a lot of times already it seems. Problem is that whenever you change pretty much anything, you have to close KaM and delete the Campaigns.dat-File in the Save-Folder...
It should do that automatically... if you change the format of the campaign data (modify the campaigndata.script file) it should reset the stored data for that campaign from Saves/Campaign.dat.
When i do it as this, i get a crash while loading the map: (sometimes...)
  Code:
var aHouse: array of Integer; procedure OnPlayerVictory(aIndex: Integer); var H: Integer; begin aHouse := States.PlayerGetAllHouses(1); for H := 0 to Length(aHouse)-1 do begin CampaignData.Mission1.iType[H] := 1; end; end;
  Code:
record Mission1: record iType: array of Integer; end; end;
You haven't set the length of the iType array. Try this:
  Code:
aHouse := States.PlayerGetAllHouses(1); SetLength(CampaignData.Mission1.iType, Length(aHouse)); for H := 0 to Length(aHouse)-1 do begin CampaignData.Mission1.iType[H] := 1; end;

Re: Saving info for later missions

PostPosted: 09 Sep 2015, 07:47
by Strangelove
Thanks for you reply, Lewin. I didn't think that it would make a difference to set the length of the array in this case. However, I finally got it to work with multidimensional arrays now. The code isnt that easy to read anymore, but it works like a charm now!

You meantioned that the campaign.dat should delete itself automaticly, however, it never did that for me. I was stuck in a loop of changing code for hours before i deleted it myself and suddenly it worked. Does KAM delete the whole campaign.dat or just the specific lines and information in it? And at what point does it do that?

Re: Saving info for later missions

PostPosted: 09 Sep 2015, 10:40
by Lewin
Thanks for you reply, Lewin. I didn't think that it would make a difference to set the length of the array in this case. However, I finally got it to work with multidimensional arrays now. The code isnt that easy to read anymore, but it works like a charm now!
You always have to initialise dynamic arrays, they begin with a size of zero.
You meantioned that the campaign.dat should delete itself automaticly, however, it never did that for me. I was stuck in a loop of changing code for hours before i deleted it myself and suddenly it worked. Does KAM delete the whole campaign.dat or just the specific lines and information in it? And at what point does it do that?
What I meant to say was that it should ignore the saved campaign script data if you change the format of campaigndata.script. It won't delete campaign.dat.

Re: Saving info for later missions

PostPosted: 09 Sep 2015, 11:47
by Strangelove
You always have to initialise dynamic arrays, they begin with a size of zero.
I didnt know that, thanks again!