ENO Posted September 27, 2013 Share Posted September 27, 2013 (edited) (EDIT: I've seen grimes reference the scripting editor wiki about 2 dozen times- and I know it's as a way of trying to get folks who are new to it to be familiar with this resource. It can answer 95% of the questions you have- if you use it. Here's the link: http://wiki.hoggit.us/view/DCS_mission_editor ) Eh guys... I have some very simple things I'm trying to do- I'm working through the .lua wiki that grimes has posted a couple times but I'm not quite ready to resolve my simple issues. I have no doubt there are some budding mission editor artists out there who are suffering in silence with this and though I don't want to burden Grimes specifically with my tiny problems, I'm seeing lots of folks in here who seem comfortable with the concept. Perhaps you can help me and others like me. Maybe we can make this a collection point for beginner script formatting questions / answers. I'll start with the mist teleport function. MIST describes the script as this: mist .teleportInZone (string groupName, string zoneName, Boolean disperse, number radius) I got this far- which is my 3rd attempt and where I finally decided to write this thread: mist.teleportInZone('group1', 'zone1', disperse = true, radius =100) I keep getting "error in error handling" notices- so unlike some scripts I've botched it doesn't give me clues. Help with this format will resolve issues with almost the entire teleport / clone / respawn function so I thank you in advance and apologize for my noob status. Edited November 7, 2013 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
ajax Posted September 27, 2013 Share Posted September 27, 2013 Try this: mist.teleportInZone('group1', 'zone1', true, 100) Link to comment Share on other sites More sharing options...
ENO Posted September 27, 2013 Author Share Posted September 27, 2013 Funny- I had it whittled down to that already while impatiently trying to sort out this "simple" problem. Unfortunately, I get "error in error handling" again. Thank you for taking a stab at it though- "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
RagnarDa Posted September 27, 2013 Share Posted September 27, 2013 Welcome to the wonderful world of programming :) The code you wrote is what's called a call to a function. It basically asks a bit of code to do something with the parameters you give it. If two of the parameters was part of a table then it would almost be correct code but it would look like this: mist.teleportInZone('group1', 'zone1', {disperse = true, radius =100}) and most importantly it wouldn't work as the function wouldn't expect those parameters. If you spent just a little time (like an hour) to get a understanding of basic concepts like functions, data types, control structure and scope (and classes) then BAM! you would be able to program in any language ;) Edit: Errors in scripts in DCS show as SCRIPT in DCS.log. Your error might be unrelated. DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is. Link to comment Share on other sites More sharing options...
ENO Posted September 27, 2013 Author Share Posted September 27, 2013 Eh Ragnarda... thanks a bunch. I'm picking through some concepts... but I appreciate the boost between now and clarity! I got the error again and it is showing up as: 00029.945 ERROR DCS: Mission script error: : error in error handling all I have in the mission is a group with 4 vehicles in it (group1) and a zone (zone1) for them to go into. The zone is in a city- any chance the vehicles are being randomly placed in spots they don't belong? I don't know... very weird. And yes, MIST 3.1.19 is loaded at mission start and this is shown in the logs... "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
RagnarDa Posted September 27, 2013 Share Posted September 27, 2013 That IS weird. I looked into both Mist 3.1.19 and 3.2 and neither contained that error message. The function mist.teleportInZone doesn't even contain any error handling at all. It is as if the error message comes from the part in DCS that runs Lua-script (the compiler) and you stumbled upon a bug in DCS or possibly the Lua-reader. I'd recommend playing around with different variables (different groups etc) or formatting (like changing the ' into " which in Lua are supposedly interchangeable). DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is. Link to comment Share on other sites More sharing options...
ENO Posted September 27, 2013 Author Share Posted September 27, 2013 Ill give it a shot and report back. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
Grimes Posted September 27, 2013 Share Posted September 27, 2013 It appears to be a bug somewhere in mist. I'm sorting it out. Its kind of odd though that you are receiving the "error in error handling" message. For me it shows a proper stat traceback of where the error is occurring. 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 Link to comment Share on other sites More sharing options...
ENO Posted September 27, 2013 Author Share Posted September 27, 2013 And just to confirm- this is a normal unit, just sitting there... no late activation... no anything- it was just a testing platform for the feature so that I could confirm I knew how to work it (or not lol). I do it on a time is more (5) condition- and of course start MIST with the mission. I'd post the mission if there were anything to it but it's literally just one group and one zone. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
Grimes Posted September 28, 2013 Share Posted September 28, 2013 Uploaded a hotfix for it; Try this version of mist: http://forums.eagle.ru/showpost.php?p=1885136&postcount=324 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 Link to comment Share on other sites More sharing options...
xcom Posted September 28, 2013 Share Posted September 28, 2013 I can really relate to your frustration ENO, I was (am) in the same spot really. First of all, I never really learned how to program, so I had very hard time figuring out scripting in LUA and getting passed some break points. As I can see it, there are 3 real hard points when you start getting interested in scripting in DCS - 1. Learning how to add the scripts so that they will work correctly with the ME triggers and conditions. 2. Learning how to use the DCS scripting engine scripts or the MIST scripts, just like the inquiry you sent in this post. (This step could be hard if you get no help, and I suggest getting someone to sit with you and show you exactly how this works). 3. Implementing the DCS scripting engine and MIST scripts into a complete LUA script that can work with little support from the ME triggers. (This step in my opinion is the real programming) I'm at step 3 at the moment, I just recently started writing some scripts to do things I want that are not available with the ME, such as http://forums.eagle.ru/showthread.php?t=114576 It is difficult to get this working by yourself, even if you start understanding how the script is working when you read it, there is still the issue of implementing it into your mission correctly which can be a real head ache. I'm not really fund of asking noob questions that are obvious to some guys here, I know I would get frustrated if people would keep asking me obvious questions like this. But I can't see any other way to start figuring out some question marks I got regarding the operation and implementation of these scripts. (Sorry for all the hassle Grimes) Maybe if there was a starting guide that would show some basic ways to implement the scripts into the ME, it would ease up some question marks and get us new scriptors on the right track. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
ENO Posted September 28, 2013 Author Share Posted September 28, 2013 (edited) Thanks grimes. I'm out for a bit but ill try it out soonest! Sorry Xcom I hadn't seen there was a second page. The beginners guide, in my estimation, is the MIST guide. Well- part of it. The first part of the guide gives functional examples of each script- so I was getting pretty good at understanding the various inputs (to read them and what they meant). But about halfway through with some of the more complicated ones those examples are less forthcoming. The layout is explained as I mentioned in the IP- and actually ragnar does a good job configuring it so I'm better prepared to set up similar scripts. It's a start. And no that's not me necessarily implying that grimes needs to do more work on that than he already has- but I'll say this much: it would be a FANTASTIC beginners guide- at least to implementing scripts vs a guide about writing them from scratch. Edited September 28, 2013 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
Grimes Posted September 28, 2013 Share Posted September 28, 2013 Quite a lot of time spent listening to Ludovico Einaudi and editing the wiki later... http://wiki.hoggit.us/view/Scripting_Engine_Introduction http://wiki.hoggit.us/view/Scripting_Documentation_Guide :sleep: To be honest the Scripting Engine Wiki, how it is setup now, is mostly there just for reference of the tools you have available to use. In the part 1 section it has some introduction to how its used in DCS, but not a lot of applicable information is in there for new scripters. The whole documentation currently requires some knowledge of how lua works in order to utilize the information that is there. For me to learn all of this stuff was basically the same story for me with the mission editor, I just had a lot of time to kill and dove in experimenting with all sorts of stuff. I had Speed to answer questions when I had some, and eventually he wrote the foundation for MIST and all of its utility scripts to aide in mission design. You'd be surprised how much you can learn by adding env.info() statements everywhere or using trigger.action.outText(mist.utils.tableShow(whateverTable), 30) periodically. xcom categorized the stages nicely, but I'd argue that step 1 and 2 are a lot more mixed. The mist.teleportInZone() function is a relatively easy function to use, and can be compared to something like an Explode Unit trigger action. The only difference is you have to type it out and know what sort of values go where. Step 3, while important, isn't a requirement or something that is desirable for all. It depends entirely on what you are trying to do. There are certainly some concepts that should be 100% done with scripting, but on the other hand most can get by and add a lot of cool and simple randomness or other features with a mix of scripting and mission editor triggers. As tedious at times creating documentation is, its quite important for the big picture. Its why I have spent a ton of time creating a wiki page for every MIST function and plan on adding more details to the pages that need more, but also start adapting the scripting engine wiki to follow the same template. Partially why I am doing it is so whenever you guys have a question about something, instead of having to explain things a bit, I could just post something like this: http://wiki.hoggit.us/view/CloneInZone and it'll at least get ya heading in the right direction. :) The other part is that a wiki is much easier to edit, navigate, and search compared to a 60+ page PDF file. Having quality documentation allows others to learn, which eventually means there will be a whole lot more people out there capable of answering questions in details. 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 Link to comment Share on other sites More sharing options...
ENO Posted September 28, 2013 Author Share Posted September 28, 2013 YAHOO! That fix worked! Thank you Grimes! "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
RagnarDa Posted September 30, 2013 Share Posted September 30, 2013 This topic has been interesting me for a while. All you beginners in Lua-scripting, what do feel has been the most difficult part to understand or do? DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is. Link to comment Share on other sites More sharing options...
xcom Posted September 30, 2013 Share Posted September 30, 2013 For me, its how to make scripts I do, run with the mission editor. I know how to make large scale missions with the mission editor, also how to use the dcs scripting engine and MIST functions as is. (Well most of the functions) Now making a script that is working as a 3rd party script with the mission is also fine, but how do I implement it? I'm stuck there. See my thread -http://forums.eagle.ru/showthread.php?t=114576 [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
ENO Posted September 30, 2013 Author Share Posted September 30, 2013 Starting from scratch my issue has been in looking over the .lua wiki for example and learning about the various aspects of it- numbers, strings, bolean, tables, function... and trying apply it to what each is responsible for and how to work them together so they play nice. Perfect example is in my first post- I can see EXACTLY what I need to put in there but lack the capacity to stitch it together and use terms the architecture supports. Tables- for example... I do understand that it's a mechanism that the language uses to reference lists identified in short form- but I don't know how to build or utilize one... where do I put it and how does it fit into the equation... Just an example of what I struggle with. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
xcom Posted September 30, 2013 Share Posted September 30, 2013 I'm having the same with figuring out how to utilize returned arrays and how to use enum exactly. Seems we would have to struggle with this until we figure it out on our own. Using the way Grimes suggested to print out to the screen is a good way to understand, but for instance I was trying to do it without MIST and couldn't figure out why it wasn't working. [sIGPIC][/sIGPIC] BuddySpike Website | Live Map & Statistics BuddySpike Twitch Channel Buddyspike Discord Buddyspike Facebook Link to comment Share on other sites More sharing options...
Grimes Posted September 30, 2013 Share Posted September 30, 2013 (edited) Tables are pretty straight forward, but can get confusing quite quickly. You declare a table the same way you declare a number, string, or boolean. local myTable = {} Curly Brackets {} designate a table. With nothing between the brackets it is an empty table. local myTable = {['playerName'] = 'grimes', ['startTime'] = timer.getTime()} is the same as myTable = {} myTable.playerName = 'grimes' myTable.startTime = timer.getTime() I strongly recommend using mist.utils.tableShow() whenever you are using tables so you can get an idea of how the table is formatted or what sort of data you might be passing to a function when using a table. http://wiki.hoggit.us/view/TableShow. You can't directly print out a whole table without using a function like mist.utils.tableShow(). You can print specific values if you know what they are and the specific value isn't a table. env.info(myTable.playerName) If you sanitize io and lfs you can use the scripting engine to save files. I use this all of the time to see what sort of data is in a table with the following function. mist.debug.writeData(mist.utils.serialize,{'myTableData', myTable}, 'fileName.lua') Edited September 30, 2013 by Grimes 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 Link to comment Share on other sites More sharing options...
RagnarDa Posted October 1, 2013 Share Posted October 1, 2013 For sake of completeness, initializing a table can also look like this: myTable = {playerName = 'grimes', startTime = timer.getTime()}You don't actually need the [' and ']. An array on the other hand is kind of like a table only that whats in it can't be named but is instead numbered. In Lua (unlike most other languages) the first item in the array is numbered 1 (instead of 0). So to initialize an array you do like this: MyFirstArray[1] = "First item" MyFirstArray[2] = "Second item" MySecondArray = {"First item", "Second item"}This will create two arrays both containing the strings (text data) "First item" and "Second item". Arrays are one-dimensional but can be multiple-dimensional by having the items within the array be arrays (and if you wish, the items within those arrays be arrays and so on). To access the items in the array you add the number inside square brackets [] to the end of the array name like this: [i]trigger.action.outText(MyFirstArray[1], 10) -- wait a little trigger.action.outText(MySecondArray[2], 10) [/i]This will show the text "First item" and then "Second item" on the screen. Enums (short for enumerated type) is a way to replace numbers with text. A good example of this is colors. We can have a list of colors, like the smoke marker colors in DCS (from the wiki): trigger.smokeColor = {Green, Red, White, Orange, Blue}Now the name Green, Red, White, Orange and Blue are actually just names replacing numbers which would be easier for the person writing the code to remember. So Green is 0, Red is 1, White is 2, Orange is 3 and Blue is 4. So now you can put smoke at the position of Somewhere by writing: trigger.action.smoke(Somewhere, trigger.smokeColor.Orange) OR you can write: trigger.action.smoke(Somewhere, 3) because trigger.smokeColor.Orange represents the number 3. Hope this helps! :) 1 DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is. Link to comment Share on other sites More sharing options...
Prof_hilactic Posted October 2, 2013 Share Posted October 2, 2013 I have to admit I am really struggling with Lua. I have limited knowledge of programing (only Basic and pascal - showing my age...) but I can write some loops. My real problem is to understand what input value is needed for some function. Most of the time is seems completely arbitrary why one require a table and string whilst the other is just one string and even with trial and error most of the time I get nowhere. For example I have this function with dynAdd local group = mist.getGroupData('Armor_1') group.route = { points = mist.getGroupRoute('Armor_1', true) } group.country = 'USA' group.groupType = 'GROUND' mist.dynAdd(group) It works no problem but If i want to add mist.scheduleFunction I am stuck. the Wiki description is chinese to me mist.scheduleFunction(mist.groupToRandomZone, {'myGroup', 'myZone'}, timer.getTime() + 10, 900, timer.getTime() + 3600) If I try to decipher it and modify it to dynAdd it goes as follow : mist.scheduleFunction(mist.dynAdd(group), timer.getTime() + 60) -- no luck mist.scheduleFunction(mist.dynAdd,(group), timer.getTime() + 60) -- no luck mist.scheduleFunction(mist.dynAdd,('group'), timer.getTime() + 60) -- no luck mist.scheduleFunction(mist.dynAdd,{'group'}, timer.getTime() + 60) -- no luck .... Stuck I don t know what other symbol or combination of symbol to use. All this because I cannot understand what table vars unpack means ( I know RTFM) . A shame because once I manage to get mist to do what I want it is a blast. Luckily there is a forum where I can ask stupid question and most of the time I get the answer until the next hurdle, where the same process start again. Link to comment Share on other sites More sharing options...
St3v3f Posted October 2, 2013 Share Posted October 2, 2013 (edited) mist.scheduleFunction(mist.dynAdd,{'group'}, timer.getTime() + 60) -- no luck You've almost had it: mist.scheduleFunction(mist.dynAdd,{group}, timer.getTime() + 60) If you put in 'group', it means a string with the word 'group', not the content of the variable group Edited October 2, 2013 by St3v3f aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Cougar Posted October 5, 2013 Share Posted October 5, 2013 (edited) Alright well guess I need a little bit of assistance with tables and events. simple do T={} function T:onEvent(event) if event.id == world.event.whatever then local initiator = event.initiator local initName = initiator:getName() local Event = event.id trigger.action.outText(initName, 10) end end world.addEventHandler(T) end Now the part Im having a hard time with is how to add the event to a table for each event and get the total lengh of the table. do local events_ = {} T={} function T:onEvent(event) while event.id == world.event.whatever do events_[#events_+1] = table.insert(events_,world.event.whatever) showTable = mist.utils.tableShow(events_) trigger.action.outText(showTable, 10) end end world.addEventHandler(T) end Ill come back tommorow as I cant think straight anymore lol but thanks in advance for trying to help :) Edited October 5, 2013 by Cougar Link to comment Share on other sites More sharing options...
RagnarDa Posted October 5, 2013 Share Posted October 5, 2013 The # operator in Lua doesn't work like that unfortunately. Write a function like this function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end and use that to get the number of items in the table. DCS AJS37 HACKERMAN There will always be bugs. If everything is a priority nothing is. Link to comment Share on other sites More sharing options...
St3v3f Posted October 5, 2013 Share Posted October 5, 2013 The # operator is fine. The problem is this line: events_[#events_+1] = table.insert(events_,world.event.whatever) You either add an item to a table by events_[#events_+1] = world.event.whatever Or by table.insert(events_,world.event.whatever) but you did a combination of both and that screws things up aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Recommended Posts