NimrodX
Posts: 82
Joined: 5/12/2018 Status: offline
|
Ok great! This will speed up my plan to put this on GitHub so people can just submit additions as push requests on there. BTW, I originally thought it would make sense to attach the code as a lua scenario attachment but it seems like that either doesn't work properly or isn't worth the effort even if it does. My current recommendation on how to add a function library to a scenario is this: quote:
--[[ --------------------------------------------------------------------------------------------------------------------------- How to use this file: There are two ways to use this. #1 - If you only need one or two functions in only one script chunk then you could simply copy the function from here and paste it into the script. But unless it is ONLY used in that ONE place, this will quickly become unmanagable! This is strongly discouraged. #2 - The best thing to do is copy and paste this entire file into an Lua Script "Action". That way it can easily be evaluated on scenario load, making the functions available everywhere. Here's a quick way to do that. 1) Load up the Lua console and execute this code snippet in it ONCE to create the initialization event: local event = ScenEdit_SetEvent('Lua Helper Init', {mode='add', IsRepeatable=true}) ScenEdit_SetTrigger({mode='add',type='ScenLoaded',name='Scenario Loaded'}) ScenEdit_SetEventTrigger(event.guid, {mode='add', name='Scenario Loaded'}) ScenEdit_SetAction({mode='add',type='LuaScript',name='Load Lua Helpers', ScriptText='-- REPLACE THIS with the contents of cmano_helpers.lua'}) ScenEdit_SetEventAction(event.guid, {mode='add', name='Load Lua Helpers'}) 2) Now, open up Editor->Event Editor->Actions, edit the "Load Lua Helpers" action, copy the whole contents of this file to the clipboard (load in notepad.exe or a better text editor, Ctrl-A, Ctrl-C), and paste it into the "Load Lua Helpers" script editor (click text area, right-click Select All, Ctrl-V). 3) Save the scenario, then reload the scenario from the file. 4) After you do this, every Lua script that runs in the scenario should be able to use every function in this file. You only need to do this process once for every new scenario. If you need to update the library of functions for your scenario, just edit the "Load Lua Helpers" Action and copy/paste the new file, make one-off edits, or whatever you need to do. Then save the scenario and load it from the file again. Tips: If you are working on your own "library" and aren't quite done yet, there's a temporary way to load these functons from a file on disk. Consider this "developer mode" because you can edit the file with a text editor and still use it in scripts and the Lua console during testing. Place the file in the [CMANO Game Folder]/Lua directory (* see note) and you will be able to load it in the Lua console or the "Load Lua Helpers" Action like this: ScenEdit_RunScript ("cmano_helpers.lua") -- or whatever the filename is Once your code is finalized, just copy/paste the whole contents of your lua file into the "Load Lua Helpers" Action (replacing the above line) so you don't have to worry about bundling an external file. * Warning: in Build 998.9 and probably before, if you are using the Steam version of the game launched from Steam, or you've launched it from autorun.exe, then Lua scripts run from ScenEdit_RunScript() must go in the [CMANO Game Folder]/GameMenu_CMANO/Lua directory instead. --------------------------------------------------------------------------------------------------------------------------- ]]--
|