Jump to content

Beginner script format assistance


ENO

Recommended Posts

I found the following in MiST. I haven't tried it yet. Undocumented function?

 

coalition.getCountryCoalition(countryId)

 

 

It's on the wiki, under coalition.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

It's on the wiki, under coalition.

Here? I can't find it.

coalition.getCountryCoalition(countryId)

 

CORRECTION, you mean the Hoggit Wiki. WTH I thought they were the same in regards of the scripting engine part1 & part2.

 

So the ED Wiki should be considered obsolete then (part1 & part2)?

 

Thanks for the heads up!

Link to comment
Share on other sites

Beginner script format assistance

 

 

 

It's here as well. There are different pages for different versions of DCS. The DCS:World version is at the top of the page. I don't know but I think the Hoggit one is most up-to-date. There was a problem with EDs wiki a while back so it was locked IIRC hence the move to Hoggit.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

I'm trying to add tasks to a group, but I'm having trouble figuring out how to do it.

 

Current code:

 

actgrp = Group.getByName(F15)
tgrp1 = Group.getByName(T1)
tgrp2 = Group.getByName(T2)
Controller =  
{
   Group.getController(actgrp) -- Get acting group controller

}

actor = {
mist.getGroupData(actgrp) -- Get group ID to assign task to
}
actorID = {
actor.groupID
}

tgt1 = {
mist.getGroupData(tgrp1) -- Get target for task
}

tgt1ID = {
tgt1.groupID
}

tgt2 = {
mist.getGroupData(tgrp2) -- Get target for task
}
tgt2ID = {
tgt2.groupID
}

tasking = 
{
   [1] = 
   {
       ["enabled"] = true,
       ["auto"] = false,
       ["id"] = "AttackGroup",
       ["number"] = 1,
       ["params"] = 
       {
           ["weaponType"] = 1069547520,
           ["groupId"] = tgt1ID,
       }, -- end of ["params"]
   }, -- end of [1]
   [2] = 
   {
       ["number"] = 2,
       ["auto"] = false,
       ["id"] = "AttackGroup",
       ["enabled"] = true,
       ["params"] = 
       {
           ["weaponType"] = 1069547520,
           ["groupId"] = tgt2ID,
       }, -- end of ["params"]
   }, -- end of [2]
}, -- end of ["tasks"]

function Controller.pushTask(Controller, tasking.1)

At the moment I'm sure the second half is wrong somewhere because I've become stuck getting an error on the first half. Apparently there is supposed to be a parenthesis somewhere around Controller. I have no idea where that would go. I've tried placing a bunch in the code but nothing resolved the issue.

 

What I'm trying to do here is add tasks that I copied from the mission file through scripting. A group named F15 is getting the tasks to attack Group T1 and T2. The mission this currently in is a junk mission for testing. Ultimate I want to use this to add a triggered action to a group that is set to Escort (in the ME this makes it impossible to add an Attack Group task) so the player can give orders.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

You're putting all the variables in tables. Like:

Controller =

{

Group.getController(actgrp) -- Get acting group controller

}

 

should be:

Controller = Group.getController(actgrp) -- Get acting group controller

 

also, you can't use a variable called Controller anyways, because there is already the Controller class of the SSE

 

and in the last line, remove 'function'

function is a codeword used to declare (create) a function


Edited by St3v3f

aka: Baron

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

Beginner script format assistance

 

Also, getByName() takes a string unless F15, T1 and T2 are strings.

 

Also, look up Group.GetId()

 

And the tasks doesn't work like that. Have a look at a working script for an example.

 

I suggest you do read up about Lua, it might be mind-numbingly boring but it helps a lot.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

I suggest you do read up about Lua, it might be mind-numbingly boring but it helps a lot.

I might have to. I was hoping by looking at examples, the MIST docs, and writing some simple code I'd pick it up, but it's not as clear as I'd like it to be.

 

I'll try the changes both of you suggested and see what I get, thanks.

Awaiting: DCS F-15C

Win 10 i5-9600KF 4.6 GHz 64 GB RAM RTX2080Ti 11GB -- Win 7 64 i5-6600K 3.6 GHz 32 GB RAM GTX970 4GB -- A-10C, F-5E, Su-27, F-15C, F-14B, F-16C missions in User Files

 

Link to comment
Share on other sites

I might have to. I was hoping by looking at examples, the MIST docs, and writing some simple code I'd pick it up, but it's not as clear as I'd like it to be.

 

I'll try the changes both of you suggested and see what I get, thanks.

It's like doing clay sculpturing with slime this Lua & DCS business. Not only is Lua an extremely loose scripting language, the DCS Mission Editor doesn't always reload your edited Lua file you have in the dofile trigger, -> for each test you have to open the trigger and click "Browse" and point to your Lua file. Incredible annoying having to repeat things like that.

Sometimes the mission, when having clicked "Fly" just freezes, nothing happens. A few reloads [Exit] -> [Mission Editor] -> [Reload Lua in Trigger] -> [start Mission] helps sooner or later.

It would be of immense help to have the ME to properly detect changes and also have an absolute minimum mission environment to load when doing development and repeated testing. Loading an almost empty mission and making a simple test takes for me at this stage in my scripts at least 45s.

 

By the way, if you use dual monitors, make sure to download UnxUtils and make a .bat file to which you enter the command :

tail -f "C:\Users\[i]yourusername[/i]\Saved Games\DCS\Logs\dcs.log"

This will let you follow the DCS log in real time as the game spools log entries into it.

  • Like 1
Link to comment
Share on other sites

It's like doing clay sculpturing with slime this Lua & DCS business. Not only is Lua an extremely loose scripting language, the DCS Mission Editor doesn't always reload your edited Lua file you have in the dofile trigger, -> for each test you have to open the trigger and click "Browse" and point to your Lua file. Incredible annoying having to repeat things like that.

Sometimes the mission, when having clicked "Fly" just freezes, nothing happens. A few reloads [Exit] -> [Mission Editor] -> [Reload Lua in Trigger] -> [start Mission] helps sooner or later.

It would be of immense help to have the ME to properly detect changes and also have an absolute minimum mission environment to load when doing development and repeated testing. Loading an almost empty mission and making a simple test takes for me at this stage in my scripts at least 45s.

 

By the way, if you use dual monitors, make sure to download UnxUtils and make a .bat file to which you enter the command :

tail -f "C:\Users\[i]yourusername[/i]\Saved Games\DCS\Logs\dcs.log"

This will let you follow the DCS log in real time as the game spools log entries into it.

 

Well, I wouldn't use DO SCRIPT FILE. I just prefer DO SCRIPT. I usually write my scripts in Notepad++ and just paste them into DCS, but sometimes, I will write them in SciTE (comes with Lua For Windows). With SciTE, you can check for syntax errors.

 

One thing you can do, if you really need to optimizing Lua testing in DCS, is you can modify ./Scripts/MissionScripting.lua so that it has access to the io and lfs libraries. With that change, you can load a new script file during the mission, like this-

 

function doScriptFile(fN)
local function log(s)
	print(tostring(s))
	trigger.action.outText(tostring(s), 10)
end

local f, err = loadfile(fN)
if f then
	local err, errMsg = pcall(f)
	if not err then
		log('LUA ERROR- unable to run ' .. fN .. ', reason: ' .. tostring(errMsg))  --catches runtime errors.
	end
else
	log('LUA ERROR- unable to load ' .. fN .. ', reason: ' .. tostring(err))  --catches syntax errors.
end
end


--[[useage example:
if you have the file named "ScriptFile.lua" in Saved Games/DCS.
Put this code in a DO SCRIPT action that is triggered by an F10 radio menu selection.
]]

do
local fName = lfs.writedir() .. [[\ScriptFile.lua]]
doScriptFile(fName)
end

 

 

You could set up an F10 radio option to "load script file", for example. So no more restarting DCS, you just have to use the F10 menu option. It will re-load whatever is CURRENTLY in your script file, and try to run it, and report back any problems it encounters.

 

Again though, you have to modify MissionScripting.lua and comment out the two lines where the lfs and io libs are sanitized.

 

Well, technically, you don't need to un-sanitize lfs, but you might as well, since lfs automatically finds the path of Saved Games/DCS for you.

 

And +1 for that tip about seeing dcs.log in real time, that could be very, very useful for me!


Edited by Speed
  • Like 1

Intelligent discourse can only begin with the honest admission of your own fallibility.

Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/

Lua scripts and mods:

MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616

Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979

Now includes remote server administration tools for kicking, banning, loading missions, etc.

Link to comment
Share on other sites

Thank you very much for you input! This will most certainly speed up the developing process in a remarkable way. Reputation heading your way! :thumbup:

I will write them in SciTE (comes with Lua For Windows). With SciTE, you can check for syntax errors.

Excellent I will try that out immediately.

 

One thing you can do, if you really need to optimizing Lua testing in DCS, is you can modify ./Scripts/MissionScripting.lua so that it has access to the io and lfs libraries. With that change, you can load a new script file during the mission, like this-

:thumbup::thumbup::thumbup:

 

And BareTail adds some colour to it also

Thanks for the tip! Didn't know about this software! It is located here and is free according to the authors. Having color will certainly help a lot to weed out errors or warnings.


Edited by ArturDCS
Added info about BareTail
Link to comment
Share on other sites

Regarding UnxUtils and real time monitoring of the DCS log file.

I'll write down the details for future reference for the benefit of others. This may or may not be known to all.

Unzip the UnxUtils archive and copy the UnxUtils to your [C:\Program Files (x86)\] folder where all 32-bit programs are.

Now if you want to use UnxUtils you will have to (in your bat/cmd/ps1 files) reference the individual programs with absolute paths like:

 

"C:\Program Files (x86)\UnxUtils\usr\local\wbin\tail.exe" -f "C:\Users\yourusername\Saved Games\DCS\Logs\dcs.log"

This isn't always practical. To make UnxUtils known to Windows do the following:

Open [File Explorer]

"My Computer" -> Right Click -> "Properties" -> "Advanced system settings" -> "Environment Variables"

In the [system variables] list scroll down to the variable [Path].

 

The [Path] variable is used by Windows to index folders, non-installer software and files. When installing a program (ie setup.exe), Windows will register this program and have it indexed in all kinds of ways and know everything about the software/program. With UnxUtils which is a library without an installer we have to tell Windows where it is. That is what the [Path] variable is for.

So carefully edit the [Path] variable:

 

  • Double click it
  • a new window opens with [Variable value] all selected (blue)
  • press [Home] key to deselect the text and go to the start of the variable values
  • Add the following to the beginning (the ; is the delimiter):

C:\Program Files (x86)\UnxUtils\usr\local\wbin;

  • Press "OK"

 

Having done that you can use the tools just like any command line tools:

tail.exe -f "C:\Users\yourusername\Saved Games\DCS\Logs\dcs.log"

By the way, there are some devilish powerful tools there so you may want to delete [rm.exe] (rm = remove ~ del/erase in Windows) which can (if it is as in Unix/Linux, I am not going to try) delete whole directory structures without prompting if used carelessly. Don't try it, just rename the file or delete it if you don't want it around.


Edited by ArturDCS
grammar
Link to comment
Share on other sites

Are there no world.event for a bomb drop? Or bomb hit?

I'm trying to use script and not use the triggers to set flags for bombing identification. Or maybe I should use the map object to check?

 

EDIT: I found it.


Edited by HiJack
Link to comment
Share on other sites

Eh guys...

 

 

If I wanted to show the value of a particular flag in the mission (for testing) I found this command in the lua basics sticky-

 

trigger.action.outText(string text, Time delay)

Would I use something like that? (replacing time delay with flag value?

"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

Thanks (again) st3v3.

 

 

EDIT: Tested it and it works like a charm. This will come in handy when I'm wondering why certain things aren't happening... is it just because of a random value not changing? Is it changing? Is it doing nothing at all? Is it always the same?

 

 

Perfect means of verification.

 

EDIT AGAIN: Is it possible to broadcast which flag it is?


Edited 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

  • 3 weeks later...

Tried a global search but did not find a good answer. When you pass a variable to a function, will that variable be local to the function? Like this

 

testVariable = "question"
newVariable = functionName(testVariable)

function functionName(variable)
-- is the variable local to this function?
variable = "result"
return variable

end;

Link to comment
Share on other sites

Here's one way to test it that I ran on my phone:

 

function MyFunc(param)
   param = 2
end

local ltestvar
ltestvar = 1
MyFunc(testvar)
gtestcar = 2
MyFunc(gtestvar)
if (testvar == 2) then
    print("it is changing the local variable")
end
if (gtestvar == 2) then
    print("it is changing the global variable")
end
print("program ended")

 

The result? Functions doesn't change neither local or global variables so the parameters is local to the function.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

Beginner script format assistance

 

Code2Go on IPhone. Convenient when you want to code in the... uhm... throne room.

 

Spotted a mistake in the code, fixed it, tested again and same result.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...