Differences

This shows you the differences between two versions of the page.

Link to this comparison view

saveloadtriggers [2016/10/18 23:30]
benw11 created
saveloadtriggers [2016/10/18 23:35]
benw11
Line 1: Line 1:
-====== ​Tutorial Template ​======  ​+====== ​Add save and load option to triggers ​======  ​
  
 Game Version: ​ FS15 and later\\ Game Version: ​ FS15 and later\\
Line 10: Line 10:
 ---- ----
  
-===== Template ​Intro =====+===== Intro =====
  
-Cu nec disputando interpretaris, ​an nam vidit aliquid fabulas! Everti elaboraret intellegam cum ei, stet repudiandae te sed, an eam tale lorem! Cu pri idque viris, an dicam dolorem vim.+This tutorial will show one way how you can save and load values in your trigger 
 +This is an extension to this tutorial - http://​fs-uk.com/​forum/​index.php?​action=articles;​sa=view;​article=74
  
-His suscipit facilisis ea, ius et quaeque aliquidInsolens eleifend qui te, eu nec tota porro?+Skill level needed is more then basic. 
 + 
 +This tut will show one way how you can save and load values in your trigger.
  
 ===== Prep Work ===== ===== Prep Work =====
  
-Harum nostrud ex mea. Vide eruditi inciderint ad quo, vix dicant possim tritani et! Eos inani summo dicam te. Sea tibique singulis an, ex has mentitum dignissim, ius modus utamur impedit ut.+Skill level needed is more then basic.
  
-  * One +===== Full Details =====
-  * Two +
-  * Three +
-  * Four +
-  * Five+
  
-Exerci impetus pri et, mel an putent nemore. Quas delenit legimus ​id mea, ne cum debitis epicuri.+The first thing we want to do is to add the trigger to the "​gameSaveTable"​ and this we do like this 
 +<​code>​ 
 +function triggerBase:​load(id
 + g_currentMission:​addOnCreateLoadedObjectToSave(self) 
 + return true; 
 +end; 
 +</​code>​
  
-===== Full Details =====+Next up is the removal from the "​gameSaveTable"​ once the game is shutdown 
 + 
 +<​code>​ 
 +function triggerBase:​delete() 
 + g_currentMission:​removeOnCreateLoadedObjectToSave(self) 
 +end; 
 +</​code>​ 
 + 
 +Okay so now we have "​activated"​ the save and load function for this trigger and now we need one load function and one save function too. 
 + 
 +We start with the save 
 + 
 +<​code>​ 
 +function triggerBase:​getSaveAttributesAndNodes() 
 + local attributes ​'​example="'​ .. tostring(self.testBool) .. '"';​ 
 + local nodes "";​ 
 + return attributes, nodes; 
 +end; 
 +</​code>​ 
 + 
 +In this example I want to save an bool value an thus I need to convert it to an string so that it can be stored if you do not do this for bool values then you will get an error in your log file when saving, you do not need to add tostring if you have an number based value. 
 +If you got more values that you want to save then simply keep building on the attributes line with an space between the last " preferable, like this. 
 +<​code>​ 
 +local attributes ​'​example="'​ .. tostring(self.testBool) .. '"​ example2="'​ .. tostring(self.testBool) .. '"';​ 
 +</​code>​ 
 + 
 +You can also save an complete table if you want to and that is were "​nodes"​ comes in but I wont show that now but you basically loop your table and save all entrys. 
 + 
 +That should cover something of the save function. 
 + 
 +Now to load function 
 + 
 +<​code>​ 
 +function triggerBase:​loadFromAttributesAndNodes(xmlFile,​ tag) 
 + local testBool ​getXMLBool(xmlFile,​ tag .. "#​example"​);​ 
 + if testBool ~nil then 
 + self.testBool ​testBool; 
 + end; 
 + return true; 
 +end; 
 +</​code>​ 
 + 
 +Okay this is what we got when we want to load what we saved in the save function. 
 +Something that you must note when loading is what sort of result are we expecting? is it an string? an bool? 
 +check on this link for explanation on getXMLBool and other types that you can use 
 + 
 +http://​gdn.giants-software.com/​documentation_scripting.php#​runtime_function_reference_XML
  
-Lorem ipsum dolor sit amet, sed illud labitur nostrud ad, has no appareat sensibus temporibus? Malis dicit tollit ut pri, in vis postea tibique complectitur,​ eu pro nemore sententiae adipiscing? Ius id percipit necessitatibus, ​+Moving on.. local testBool now holds the result from example but we can never be sure if it has an value and that's why we got this
  
-{{ :​ss_2016-10-12_at_12.58.10_.png?​200 |}}+<​code>​ 
 +if testBool ~= nil then 
 +</​code>​
  
-Purto eruditi ullamcorper pri ut, ex has eirmod molestie efficianturVoluptatibus signiferumque vis te, eos ea possim oporteat accusata. Eam tincidunt adolescens ad, cu alia probo assentior duo? Qui velit nihil dissentias ne? Volumus inimicus inciderint sea eu, vix ex ipsum ubique.+it makes sure that we got an value and if so then it update self.testBool with that value.
  
 +Too make as much sense as possible then you will have to compare the save and load function and see what did he do there etc 
  
  
 ---- ----
  
-Original Author:  ​XX | Date:  ​XX+Original Author:  ​Xentro ​| Date:  ​July 06, 2013
         ​         ​
 [[modding_tutorials|Modding Index]] | [[miscellaneous_modding|Misc. Modding Tutorials]] [[modding_tutorials|Modding Index]] | [[miscellaneous_modding|Misc. Modding Tutorials]]