Tutorial: Introduction to Lua scripting - Page 8 - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 12-06-2017, 12:39 AM   #71
Kolyma
Junior Member
 
Kolyma's Avatar
 
Join Date: Dec 2014
Location: Tennessee, USA
Posts: 70
Default

Grimes, what do you use to enumerate this data from within DCS Lua? I know about the showTable function and I've been playing with snippets but I'm curious if you've poked around in the various metatables? How often have we found "new" stuff just "appear" in the scripting API or change/add something on an existing item after a patch?
__________________
Something clever goes here...
Kolyma is offline   Reply With Quote
Old 12-06-2017, 08:15 AM   #72
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 7,659
Default

I dump the _G table to a file and check to see if anything is new in there. I try to check it once a month or if ED does a major patch. I'll also do it whenever a feature request for a scripting function is said to be fulfilled. Sadly that doesn't happen much as of late, but it does occasionally. Then its down to communicating with ED for all the proper syntax and waiting for it to be merged into live builds to publish documentation.

Enumerators show up like this:
Code:
    ["trigger"]["smokeColor"] = table: 000000006F20D8B8         {
        ["trigger"]["smokeColor"]["Blue"] = 4,
        ["trigger"]["smokeColor"]["Green"] = 0,
        ["trigger"]["smokeColor"]["Red"] = 1,
        ["trigger"]["smokeColor"]["Orange"] = 3,
        ["trigger"]["smokeColor"]["White"] = 2,
        },
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 12-06-2017, 12:38 PM   #73
Kolyma
Junior Member
 
Kolyma's Avatar
 
Join Date: Dec 2014
Location: Tennessee, USA
Posts: 70
Default

Thanks for info. I can see the nested tables and understand how to walk that recursively.

When I see stuff like this, I know where to go to learn more (EventHandlers.lua):
Code:
 ["world"]["addEventHandler"] = "function: 000000000029DFF0, defined in (3-5) Scripts/World/EventHandlers.lua
But I'm curious for the these kinds of C functions how I determine what their expected parameters are and the return value. How might I proceed chasing that?
Code:
["world"]["getPlayer"] = "function: 000000007481A5A0, C function",
One of the reasons for trying to better understand this for me is I want to see if the _G scan result is the same for these ME mission scripts as all the other places where we add scripts, like the slmod and place where the DCS-BIOS pulls it's info. That, plus I'd also like to try to hook other C dlls and explore whether completely novel features could be added to scripts. I've done this kind of work on C# .Net games, which was kind of easy if you know how .Net works and that it leads directly to obtaining "source code" through reflection. With DCS, it's all C dll's and still possible, just a little more difficult. The first part is understanding how the existing Lua scripting engine interfaces with these "C function" 's listed in showTable.

...If there's a better existing place to post questions like this, please let me know. If I should start a new thread, just let me know that.
__________________
Something clever goes here...
Kolyma is offline   Reply With Quote
Old 12-07-2017, 07:34 AM   #74
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 7,659
Default

Quote:
Originally Posted by Kolyma View Post
But I'm curious for the these kinds of C functions how I determine what their expected parameters are and the return value. How might I proceed chasing that?
Code:
["world"]["getPlayer"] = "function: 000000007481A5A0, C function",
Its literally just from communicating with ED. In the case of me making a feature request I add in what I think the expected return value and input values should be. In the few times ED have just gone and added a scripting function I will try to experiment with it a little on my own or just directly ask for the relevant documentation.

DCS-BIOS and slmod have access to different lua environments. The net environment which slmod uses has pretty well maintained documentation by ED in the API/DCS_controlAPI.txt files from the install folder. The export lua environment documentation can be found in Scripts/Export.lua. I haven't messed with it to much, so I can't really answer a whole lot of questions on it. I can say its more geared toward interacting with the players own aircraft for making home cockpits and the like. But it does have access to the greater "world" of objects in the game, which is how tacview uses it to record data.
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 12-07-2017, 03:12 PM   #75
Kolyma
Junior Member
 
Kolyma's Avatar
 
Join Date: Dec 2014
Location: Tennessee, USA
Posts: 70
Default

Ok great, that answers a lot. So from just a cursory first look, there are at least 2 undocumented C functions. They might not be actually useful or anything, but I was trying to see if I could find anything novel.

getDrawArgumentValue
["Unit"]["getDrawArgumentValue"] = "function: 0000000080418010, C function",

cancelChoosingCargo
["Unit"]["parentClass_"]["cancelChoosingCargo"] = "function: 000000007750BBA8, C function",

So to confirm, we don't have any current back-and-forth collaborations with ED persons about enhancing Lua scripting capabilities?

And yeah, I saw the DCS_controlAPI.txt and Scripts/Export.lua portion. That's when I first had the thought that maybe the Lua environments being exposed to each of those 3 purposes might be different. I suppose without knowing more there might be some value/function in one _G that is not available in another _G. So maybe mission scripts could have increased capabilities by some kind of out-of-band "bridge" between those various standard DCS scripting interfaces.

That leads me to what I thought might be useful to make: I suppose right now we don't have a general-use tool that will dump _G recursively and find all the C function parameters and return values? From what you describe Grimes, the current info about that was either given to you to start or after questioning ED, or from your own trial and error. I think I might be able to make us a tool that would be able to pull a complete set of this info on demand by querying the associated dlls for function prototypes. Then we could run it in any of the scripting environments to see if anything new had been added/removed but unannounced.

Then there is this kind of possibility to explore the idea even further to add novel scripting features (3 part series):
http://stan-bobovych.com/2017/06/10/hooking-lua-part-1
__________________
Something clever goes here...
Kolyma is offline   Reply With Quote
Old 12-08-2017, 07:27 AM   #76
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 7,659
Default

There is communication but its simply not as extensive as it was. Essentially the guy who wrote the scripting engine made documentation and added suggestions rather quickly. After he left ED it wasn't quite the same. So feature requests now go through normal channels instead of direct communication with the guy.
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 12-09-2017, 08:54 PM   #77
Kolyma
Junior Member
 
Kolyma's Avatar
 
Join Date: Dec 2014
Location: Tennessee, USA
Posts: 70
Default

Before I get into making something that might already exist, do we have a comprehensive, general-use, tool with tableShow -like features but instead of this kind of data:

Code:
        [env][mission][failures] = table: 000000007F3C6BE0 {
            [env][mission][failures][pp_damage_EmergMaxTempr] = table: 000000007F3C6C30 {
                [env][mission][failures][pp_damage_EmergMaxTempr][hh] = 0,
                [env][mission][failures][pp_damage_EmergMaxTempr][prob] = 100,
                [env][mission][failures][pp_damage_EmergMaxTempr][enable] = false,
                [env][mission][failures][pp_damage_EmergMaxTempr][mmint] = 1,
                [env][mission][failures][pp_damage_EmergMaxTempr][id] = pp_damage_EmergMaxTempr,
                [env][mission][failures][pp_damage_EmergMaxTempr][mm] = 0,
                },
            [env][mission][failures][FWD_TANK_LEAK] = table: 00000000CCD75CF0 {
                [env][mission][failures][FWD_TANK_LEAK][hh] = 0,
                [env][mission][failures][FWD_TANK_LEAK][prob] = 100,
                [env][mission][failures][FWD_TANK_LEAK][enable] = false,
                [env][mission][failures][FWD_TANK_LEAK][mmint] = 1,
                [env][mission][failures][FWD_TANK_LEAK][id] = FWD_TANK_LEAK,
                [env][mission][failures][FWD_TANK_LEAK][mm] = 0,
                },
            [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE] = table: 00000000CCD75D40 {
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][hh] = 0,
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][prob] = 100,
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][enable] = false,
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][mmint] = 1,
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][id] = CTRL_RUDDER_ROD_MAJOR_DAMAGE,
                [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE][mm] = 0,
                },
We can get only API-level summary:

Code:
        [env][mission][failures] {
            [env][mission][failures][pp_damage_EmergMaxTempr]
            [env][mission][failures][FWD_TANK_LEAK]
            [env][mission][failures][CTRL_RUDDER_ROD_MAJOR_DAMAGE]
                [env][mission][failures][xx][hh],
                [env][mission][failures][xx][prob],
                [env][mission][failures][xx][enable],
                [env][mission][failures][xx][mmint],
                [env][mission][failures][xx][id],
                [env][mission][failures][xx][mm],
                },
Basically I'm looking for something that dumps a table and returns only it's structure and possible values, not enumerate every single value entry. Grimes, since you made the online API reference, I'm wondering if used a tool to distill that info from tableShow or went through the dump by hand?
Kolyma is offline   Reply With Quote
Old 12-10-2017, 09:40 AM   #78
Grimes
ED Testers Team
 
Grimes's Avatar
 
Join Date: Jan 2006
Location: Black Mesa
Posts: 7,659
Default

Went through it by hand.
__________________
You can only tie the world record for lowest flight.
Current Projects: Scripting Wiki, Something...
Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD for DCS 1.5/2.0, IADScript, Mission Editing Wiki!, Mission Building Forum
Grimes is offline   Reply With Quote
Old 04-30-2018, 03:03 PM   #79
kakal Ice
Junior Member
 
Join Date: Nov 2013
Location: Lens in France
Posts: 39
Default

Hello Yurgon, hello guys.
i need your assistance, i'm a beginner with lua langage.
I try to do your Tutorial: Introduction to Lua scripting but when i do that i've got this error popup.
Click image for larger version

Name:	Erreur de script mission.jpg
Views:	168
Size:	3.9 KB
ID:	183617
i send you my .miz
Hello World5.miz

The previous stages worked fine
Thank you to help me, i need to understand
kakal Ice is offline   Reply With Quote
Old 04-30-2018, 03:25 PM   #80
Yurgon
Campaign Testers
 
Yurgon's Avatar
 
Join Date: May 2010
Location: Germany
Posts: 6,590
Default

Quote:
Originally Posted by kakal Ice View Post
The previous stages worked fine
Thank you to help me, i need to understand
Found it, this one was easy to miss.

The second line has a line break. Because of the tiny text window, the visual representation is the same with or without it, but if you copy the code to Notepad (or Notepad++, or any other editor), it'll become visible:

Code:
-- This one is okay
env.warning("Some output via env.warning")

-- And this one causes the error
env.warning("some other
output")
__________________
Yurgon is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:44 PM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.