Lumax Posted March 17, 2015 Posted March 17, 2015 (edited) Hello. I like to know how i can import one file from another. i have on init.lua file that is activated on mission start. this init file should load some other files conaining functions etc. My mission.miz looks like Scripts Config warehouses options mission init.lua CoreData.lua this is my trigger rule. My test code: And here is the error it produces: Can anyone tell me what im doing wrong ? Edited March 18, 2015 by Lumax issue solved.
xcom Posted March 17, 2015 Posted March 17, 2015 Not sure, but try to put the file in your DCS installation root. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
piXel496 Posted March 17, 2015 Posted March 17, 2015 (edited) hi, Lumax just some options to try: from your images I would do function combstr(_a, _b) local _answer = string.format(_a .. " " .. _b) return _answer end And fire your init.lua as an initialization script (bottom option in triggers) Or do all scripting including functions in one file. Is the coreData.lua file in your .miz file? (open with a .zip program) :) Edited March 18, 2015 by piXel496 start simple, make it work old stuff I made
Lumax Posted March 18, 2015 Author Posted March 18, 2015 Not sure, but try to put the file in your DCS installation root. That is not accatable. @piXel496 Yes both init.lua and CoreData.lua are inside the mission file. I see no point in assigning the resulat of a & b into a local variable before returning the result. My function is not the problem. its something wrong with dofile I also want to avoid having it all in one file. my init.lua is working fine but errors when trys to open CoreData.lua If i move the function combstr to init.lua and remove dofile everythings works. But as i said i dont want it all in one file. Not sure how putting init.lua into initialization box will help since the init file starts.
Grimes Posted March 18, 2015 Posted March 18, 2015 Run CoreData.lua as a do script file in the triggers. Then remove the dofile() corresponding to it in init.lua. Problem solved. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
xcom Posted March 18, 2015 Posted March 18, 2015 Ah my bad, instead of dofile, make it loadfile("CoreData.lua") And put the file in the DCS root folder. The above should also work. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
Lumax Posted March 18, 2015 Author Posted March 18, 2015 Run CoreData.lua as a do script file in the triggers. Then remove the dofile() corresponding to it in init.lua. Problem solved. My hole point in trying to do this is so i dont have to use triggers. Also moving my CoreData to DCS root dir as suggested is not accatable. Problem araises when i want to share my mission with my friends. I dont hant to guide them thought a install process for my mission.
Lumax Posted March 18, 2015 Author Posted March 18, 2015 (edited) Solved my problem.. After messing around a bit i came up with a solution. -- TEST 1 -- -- This works but -- this is not practical since this would not be a constant. names changes. dofile("C:\\Users\\ME\\AppData\\Local\\Temp\\DCS\\Mission\\CoreData.lua") -- TEST 2 -- local currentpath = debug.getinfo(1).short_src -- tim the sting and set new path where dcs unpacks the mission. local newpath = string.sub(currentpath, 0, string.find(currentpath, "DCS")+2) .. "\\Mission\\" dofile(newpath .. "CoreData.lua") -- get the path to the init file using debug -- debug.getinfo(1).short_src usaly returns something like -- C:\Users\ME\AppData\Local\Temp\DCS\/~mis0000**** The error Test2 produces. 00240.039 ERROR DCS: Mission script error: : can't open '[string "C:\Users\ME\AppData\Local\Temp\DCS\Mission\CoreData.lua' stack traceback: [C]: ? [C]: in function 'dofile' [string "C:\Users\ME\AppData\Local\Temp\DCS\/~mis00007DED"]:16: in main chunk Now what struck me was this: can't open '[string "C:\Users\ME\AppData\Local\Temp\DCS\Mission\CoreData.lua' Somehow dofile is trying to do something like. dofile('[string "C:\Users\...) instead of dofile("C:\Users\...) Now the solutions was rather simple. in Test2 i just replaced. dofile(newpath .. "CoreData.lua")with dofile( string.sub(newpath .. "CoreData.lua", 10) )so if i want to load several files i end up with something like local currentpath = debug.getinfo(1).short_src local newpath = string.sub(currentpath, 1, string.find(currentpath, "DCS")+2) .. "\\Mission\\" dofile( string.sub(newpath .. "File1.lua", 10) ) dofile( string.sub(newpath .. "File2.lua", 10) ) dofile( string.sub(newpath .. "File3.lua", 10) ) dofile( string.sub(newpath .. "File4.lua", 10) ) Edited March 18, 2015 by Lumax
FSFIan Posted March 19, 2015 Posted March 19, 2015 Note that this solution will most likely only work in single player mode. IIRC the mission is not extracted to a temporary directory in MP (because the "mission planner" stage does not exist). DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Lumax Posted March 19, 2015 Author Posted March 19, 2015 Youre right about that. my goal was to get this working for SP. I do not know much about mp coding in dcs. But i noticed that when you join your mp server. it does not uppack the downloaded mission to "%TMP%\DCS\Mission" But rather dump all resorces such as files & pic directly to "%TMP%\DCS\" with some "random id?" names set on them. example: ~mis000012FE after messing around with the editor and some simple scripting, all i can say about it. damn this thing sucks. it needs a big update. simple things such as making one file load another file within your mission.miz. come on.. tellin people to dump (for them unknown) files at places on their pc to get missions working is a big no, no. creating tonz of triggers just to include file.. blah. imo triggers should be used for game related ations. not to load the mission function files :p They should look at the way bohemia interactive studios is doing it with arma. its a verry nice system. oh well lets see if there is a workaround for mp aswell. (without using triggers ofc)
Grimes Posted March 19, 2015 Posted March 19, 2015 creating tonz of triggers just to include file.. blah. imo triggers should be used for game related ations. not to load the mission function files :p Triggers are the easiest way to load multiple scripting files. Not that "triggers" should be plural because you can have a single trigger run multiple actions and it works like a charm. The next easiest is to put each as a do script file as an action on the first waypoint of any unit in the mission. Either works just as well. The ME GUI is what it is... something that was designed long before the scripting engine was even added. Thus the scripting engine in its relation to the editor is very much "bolted on" and a little clunky with the interaction. But it is functional to an acceptable level. You may be able to use the function that the triggers use to run an embedded lua file. Not sure if its a technically supported feature or not. a_do_script_file('embeddedFileNameHere') The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
FSFIan Posted March 19, 2015 Posted March 19, 2015 You may be able to use the function that the triggers use to run an embedded lua file. Not sure if its a technically supported feature or not. a_do_script_file('embeddedFileNameHere') I tried, that function is not available in the mission scripting environment. The ME also generates what looks like snippets of Lua code at the top of a mission file which apparently are not being used anymore -- changing them has no effect. This may be related to the disappearance of the "compile.lua" file. Interestingly, searching the DCS installation directory for any files that include the string "a_do_script_file" or the regex "a._.d.o._.s.c.r.i.p.t._.f.i.l.e" (to account for possible UTF-16 encoding) only yields the "me_trigrules.lua" file. Adding a trigger.actions.doScriptFile function would be great (I guess it wouldn't be too hard to implement). In general, I would like to see the DCS scripting system grow more powerful -- give it access to the warehouse system, more granular control of unit AI (especially ground units), make dynamically added units first-class citizens (no more "player XY killed building"), and allow Lua to dynamically add, remove and modify (change waypoints) player slots in a running multiplayer mission. I can only hope that ED will dedicate some time to scripting improvements after EDGE comes out. DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
xcom Posted March 19, 2015 Posted March 19, 2015 You may be able to use the function that the triggers use to run an embedded lua file. Not sure if its a technically supported feature or not. a_do_script_file('embeddedFileNameHere') I tried that before also, after searching a bit in the mission file. It doesn't work through the scripting engine, but you could create a script to edit the mission file in order to add the files correctly there - beats the cause though. I hope ED will put their efforts on opening more systems to the scripting engine, such as Ian mentioned, problems such as the ones in this thread are not so important in my opinion. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook
Recommended Posts