Jump to content

How to debug lua script?


csper

Recommended Posts

Hi,

 

I'm trying to code something using API for DCS. But how can I debug my code? For instance how can I see syntax error?

 

The code is:

local http = require("socket.http")

local ltn12 = require("ltn12")

 

function sendRequest(id)

local path = "http://localhost:5005/"

local payload = [[ {"key":"My Key","name":"My Name","description":"The description","state":1} ]]

local response_body = { }

 

local res, code, response_headers, status = http.request

{

url = path,

method = "POST",

headers =

{

["Content-Type"] = "application/json",

["Content-Length"] = payload:len()

},

source = ltn12.source.string(payload),

sink = ltn12.sink.table(response_body)

}

end

 

local LOGBOOK = {}

 

LOGBOOK.onSimulationStart = function()

local id = net.get_my_player_id()

log.write('LOGBOOK', log.INFO, 'onSimulationStart' ..id)

sendRequest(id)

end

 

DCS.setUserCallbacks(LOGBOOK) -- here we set our callbacks


Edited by c@sper

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

for example

03954.927 ERROR   COCKPITBASE: Cockpit: avDevice: Cannot do Lua file :  post_initialize, reason  [string ".your_lua_file.lua"]:283: attempt to call method some error' (a nil value).

 

just search for LUA and/or ERROR

'controlling' the Ka50 feels like a discussion with the Autopilot and trim system about the flight direction.

Link to comment
Share on other sites

for example

03954.927 ERROR   COCKPITBASE: Cockpit: avDevice: Cannot do Lua file :  post_initialize, reason  [string ".your_lua_file.lua"]:283: attempt to call method some error' (a nil value).

 

just search for LUA and/or ERROR

 

I still can't find the error. Can you?

No log, no server request.

the log file and the code attached.

 

Note: I tried it in multiplayer.

dcs.rar

LogbookGameGUI.rar


Edited by c@sper

[sIGPIC][/sIGPIC]

Link to comment
Share on other sites

use

 

net.log("LogBookGui: Some helpfull text")
net.log("LogBookGui: Some variables:".. VAR .."x")

 

in your code, and then search in the dcs.log for LogbookGui you can even display variables.

you can also try

 

net.recv_chat(message[, int from=0])

to write yourself a Chatmessage, but never tried it

'controlling' the Ka50 feels like a discussion with the Autopilot and trim system about the flight direction.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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