GrimyBunyip Posted February 25, 2016 Share Posted February 25, 2016 (edited) Edit: Figured it out. I'm getting the following redscreen errors upon research completion: http://imgur.com/a/oz9Fk Here is the function that runs when the research completes, it's more or less a copy paste from the exampleweapon project.I'm not sure why I'm getting a "never added to history" error. Can anyone help me understand? function IndentifyWeaponAR(XComGameState NewGameState, XComGameState_Tech TechState) { local XComGameStateHistory History; local XComGameState_HeadquartersXCom OldXComHQState; local XComGameState_HeadquartersXCom NewXComHQState; local XComGameState_Item ItemState; local X2ItemTemplateManager ItemMgr; local X2ItemTemplate ItemTemplate; local X2WeaponUpgradeTemplate UpgradeTemplate; //In this method, we demonstrate functionality that will add ExampleWeapon to the player's inventory when loading a saved //game. This allows players to enjoy the content of the mod in campaigns that were started without the mod installed. ItemMgr = class'X2ItemTemplateManager'.static.GetItemTemplateManager(); History = `XCOMHISTORY; //Create a pending game state change NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding ExampleWeapon Objects"); //Get the previous XCom HQ state - we'll need it's ID to create a new state for it OldXComHQState = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom')); //Make the new XCom HQ state. This starts out as just a copy of the previous state. NewXComHQState = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', OldXComHQState.ObjectID)); //Make the changes to the HQ state. Here we add items to the HQ's inventory ItemTemplate = ItemMgr.FindItemTemplate('AssaultRifle_Central'); //Instantiate a new item state object using the template. //ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState); //`CREATE_X2TEMPLATE(class'X2WeaponUpgradeTemplate', UpgradeTemplate, 'AimUpgrade_Bsc'); //ItemState.ApplyWeaponUpgradeTemplate(UpgradeTemplate); //ItemState.Nickname = "HelloWorld"; NewGameState.AddStateObject(ItemState); //Add the newly created item to the HQ inventory NewXComHQState.AddItemToHQInventory(ItemState); //Commit the new HQ state object to the state change that we built NewGameState.AddStateObject(NewXComHQState); //Commit the state change into the history. History.AddGameStateToHistory(NewGameState); } Edited February 26, 2016 by GrimyBunyip Link to comment Share on other sites More sharing options...
eXecator Posted February 25, 2016 Share Posted February 25, 2016 (edited) While I cant explain to you exactly what sequence of events will lead to your specific redscreen, I can point you to something that looks 'incorrect'. //ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState); NewGameState.AddStateObject(ItemState); In the second line you try to add the StateObject ItemState to your NewGameState. But since the first line is commented out, ItemState will be null at this point in time, and thats not a good thing to be. In the middle of your first redscreen image, you can see XCom complaining about this: StateObject is NULL!XCom is so unhappy, it even spend some money to get an exclamation mark in there. Edited February 25, 2016 by eXecator Link to comment Share on other sites More sharing options...
GrimyBunyip Posted February 25, 2016 Author Share Posted February 25, 2016 While I cant explain to you exactly what sequence of events will lead to your specific redscreen, I can point you to something that looks 'incorrect'.//ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState);NewGameState.AddStateObject(ItemState); In the second line you try to add the StateObject ItemState to your NewGameState. But since the first line is commented out, ItemState will be null at this point in time, and thats not a good thing to be. In the middle of your first redscreen image, you can see XCom complaining about this: StateObject is NULL!XCom is so unhappy, it even spend some money to get an exclamation mark in there. Oops, I did have that line uncommented at some point during my testing. But I started commenting stuff out hoping to figure out what was wrong. Here's the redscreen if I uncomment those lines of code: http://imgur.com/L3Slt3Z function IndentifyWeaponAR(XComGameState NewGameState, XComGameState_Tech TechState) { local XComGameStateHistory History; local XComGameState_HeadquartersXCom OldXComHQState; local XComGameState_HeadquartersXCom NewXComHQState; local XComGameState_Item ItemState; local X2ItemTemplateManager ItemMgr; local X2ItemTemplate ItemTemplate; local X2WeaponUpgradeTemplate UpgradeTemplate; //In this method, we demonstrate functionality that will add ExampleWeapon to the player's inventory when loading a saved //game. This allows players to enjoy the content of the mod in campaigns that were started without the mod installed. ItemMgr = class'X2ItemTemplateManager'.static.GetItemTemplateManager(); History = `XCOMHISTORY; //Create a pending game state change NewGameState = class'XComGameStateContext_ChangeContainer'.static.CreateChangeState("Adding ExampleWeapon Objects"); //Get the previous XCom HQ state - we'll need it's ID to create a new state for it OldXComHQState = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom')); //Make the new XCom HQ state. This starts out as just a copy of the previous state. NewXComHQState = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', OldXComHQState.ObjectID)); //Make the changes to the HQ state. Here we add items to the HQ's inventory ItemTemplate = ItemMgr.FindItemTemplate('AssaultRifle_Central'); //Instantiate a new item state object using the template. ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState); `CREATE_X2TEMPLATE(class'X2WeaponUpgradeTemplate', UpgradeTemplate, 'AimUpgrade_Bsc'); ItemState.ApplyWeaponUpgradeTemplate(UpgradeTemplate); ItemState.Nickname = "HelloWorld"; NewGameState.AddStateObject(ItemState); //Add the newly created item to the HQ inventory NewXComHQState.AddItemToHQInventory(ItemState); //Commit the new HQ state object to the state change that we built NewGameState.AddStateObject(NewXComHQState); //Commit the state change into the history. History.AddGameStateToHistory(NewGameState); } Link to comment Share on other sites More sharing options...
GrimyBunyip Posted February 26, 2016 Author Share Posted February 26, 2016 Figured it out. Posting code for anyone who is curious: local XComGameStateHistory History; local XComGameState_HeadquartersXCom XComHQ; local X2ItemTemplateManager ItemTemplateManager; local XComGameState_Item ItemState; local XComGameState_Tech CompletedTechState; local array<XComGameState_Tech> CompletedTechs; local X2ItemTemplate ItemTemplate; ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager(); ItemTemplate = ItemTemplateManager.FindItemTemplate('ModWeapon_CV'); foreach NewGameState.IterateByClassType(class'XComGameState_HeadquartersXCom', XComHQ) { break; } if (XComHQ == none) { History = `XCOMHISTORY; XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom')); XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID)); NewGameState.AddStateObject(XComHQ); } // If it is possible for this item to be upgraded, check to see if the upgrade has already been researched if (ItemTemplate.UpgradeItem != '') { CompletedTechs = XComHQ.GetCompletedProvingGroundTechStates(); foreach CompletedTechs(CompletedTechState) { if (CompletedTechState.GetMyTemplate().ItemsToUpgrade.Find(ItemTemplate.DataName) != INDEX_NONE) { // A tech has already been completed which has upgraded this item, so replace the template with the upgraded version ItemTemplate = ItemTemplateManager.FindItemTemplate(ItemTemplate.UpgradeItem); break; } } } ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState); ItemState.ApplyWeaponUpgradeTemplate(X2WeaponUpgradeTemplate(ItemTemplateManager.FindItemTemplate('AimUpgrade_Bsc'))); NewGameState.AddStateObject(ItemState); // Act as though it was just built, and immediately add it to the inventory ItemState.OnItemBuilt(NewGameState); TechState.ItemReward = ItemTemplate; // Needed for UI Alert display info TechState.bSeenResearchCompleteScreen = false; // Reset the research report for techs that are repeatable XComHQ.PutItemInInventory(NewGameState, ItemState); `XEVENTMGR.TriggerEvent('ItemConstructionCompleted', ItemState, ItemState, NewGameState); Link to comment Share on other sites More sharing options...
Recommended Posts