DarkLiz on the Runeforge Board (25th July 2014):
ZitatAlles anzeigenIts really simple to make your own custom function libraries like the ones in the Library folder.
From a library file, all your custom functions can be accessed from any script... very handy!
All you need to do is make a .lua file (I simply copy and paste one of the existing ones), name it whatever you want, delete any existing functions (if you copied and pasted), and then add a new line in stdafx.lua (found in the Library folder) with the name of your custom library in it. What that line needs to look like is evident when you open that file.
Most of the library files have the Init() function in them with a comment saying, "needed for caching".
I'm not sure exactly what that comment means, but it sounds like your custom libraries should probably also have the Init() function in them (I keep the function in mine). If anyone can enlighten me about what the purpose of that function is exactly I'd be grateful.
Having a library of your own custom functions is super useful! I recommend it to anyone who scripts The Guild 2.
For those who aren't familiar with using functions in scripts:
To use a function the name of the file the function is in needs to be attached to the beginning of the function name with an underscore behind the file name (see example below). Also, the file name needs to be in all lower case, even if its partly or entirely in upper case in the actual file name. This applies to library files as well.
Example of use for a function called TestFunction() in a file called CustomLibrary:
customlibrary_TestFunction()
McCoy on the Nordic Board (26th Octomber 2009)
ZitatAlles anzeigenPlease note this tutorial does NOT explain how to write your own functions it assumes that you already know how
1. First you need to create a new .lua file and place it in the following directory:
The Guild 2 - Pirates of the European Seas/Scripts/Library
2. Then you need to activate your library so open the following file:
The Guild 2 - Pirates of the European Seas/Scripts/Library/Stdafx.lua
3. Add the following line at the bottom of the Stdafx.lua file:4. In your new library file add the following at the top
5. Now you can get started on writing your own functions (If you are a beginner I would recommend that you study the other functions already made to get a grasp on how to make your own)
6. At last you now have the opportunity to use your new function(s) in your very own mod. In order to do this you must use the following format:
NameOfLibraryFileWithout.lua_FunctionName(YouShouldKnowWhatYouNeedToPutHere)This looks goofy so I will give you an example...Lets say your library file name is find.lua and your function is setup like this...function Wife(ObjectAlias)
This is an example of how you would use your new function:
find_Wife("")Its that simple [Blockierte Grafik: http://forum.nordicgames.at/images/smilies/smile.gif]
Note: This was all explained to me by InsaneKaos so I would like to thank him for his contribution to this tutorial [Blockierte Grafik: http://forum.nordicgames.at/images/smilies/smile.gif]
[/quote]