csper Posted June 26, 2017 Posted June 26, 2017 (edited) 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 June 26, 2017 by c@sper [sIGPIC][/sIGPIC]
Nero.ger Posted June 26, 2017 Posted June 26, 2017 syntax error are postet in the dcs.log 'controlling' the Ka50 feels like a discussion with the Autopilot and trim system about the flight direction.
csper Posted June 26, 2017 Author Posted June 26, 2017 syntax error are postet in the dcs.log I can't see. What should I search for? [sIGPIC][/sIGPIC]
Nero.ger Posted June 26, 2017 Posted June 26, 2017 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.
csper Posted June 26, 2017 Author Posted June 26, 2017 (edited) 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.rarLogbookGameGUI.rar Edited June 26, 2017 by c@sper [sIGPIC][/sIGPIC]
Nero.ger Posted June 26, 2017 Posted June 26, 2017 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.
Stonehouse Posted June 29, 2017 Posted June 29, 2017 Some editors like pycharm and LDT have lua plugins that allow you to check syntax.
Recommended Posts