Hi everyone, I am a member of a discord group that does scriptAI racing with autobeam cars, and we have been wanting some sort of race ticker UI App for real-time car placing during the race. Since we use scriptAI to race the cars, my first thought is to make a UI app that reads in the current node or time each car is on in the line. I looked through the scriptAIManager.lua file and found this section Code: local function onVehicleSubmitInfo(vehId, data) --print(' * got info: ' .. tostring(vehId)) -- .. ' : ' .. dumps(data)) -- record percentages if data then data.percent = 0 if data.scriptTime and data.endScriptTime and vehDataReceived[vehId] then data.percent = data.scriptTime / data.endScriptTime * 100 end end vehInfo[vehId] = data if data and not vehDataReceived[vehId] then vehDataReceived[vehId] = true end -- detect when we are done if vehDataReceived[vehId] and vehState[vehId] and vehState[vehId] == 'playing' and not data then vehState[vehId] = 'idle' vehInfo[vehId] = nil vehDataReceived[vehId] = nil end -- recording: -- time = wall time spent so far -- following: -- endScriptTime = total time in recording -- scriptTime = where we are in the script -- percent done = scriptTime/endScriptTime -- posError = distance to the line in meters: minus = left of path, + = right of path -- time = wall clock of playback -- timeError = time - scriptTime end I'm still very new to Lua, but it seems to me the scriptAIManager app is displaying the percent of the line finished by reading in data.scriptTime. Couldn't I just read that value for each car and sort them then? How can I make a UI app that can read in data.scriptTime?
Here's some JS UI code I wrote up that should help you get the scriptTime for each vehicle. Hope this helps Code: //Creates a Lua global table in GameEngine Lua bngApi.engineLua('script_state_table = {}'); //This is called all the time scope.$on('streamsUpdate', function (event, streams) { //This calls GameEngine Lua to tell all Vehicle Luas to insert their serialized ai.scriptState() into the GameEngine Lua script_state_table bngApi.engineLua('be:queueAllObjectLua("obj:queueGameEngineLua(\'script_state_table[\'..obj:getID() .. \'] = \' .. serialize(ai.scriptState()))")'); //This gets that script_state_table from GameEngine Lua bngApi.engineLua('script_state_table', function(data) { for (const [key, value] of Object.entries(data)) { var veh_id = key; var scriptTime = value.scriptTime; console.log("Vehicle ID: " + veh_id + ", Time: " + scriptTime); } }); });
Awesome! Thank you! I'm still reading through that trying to figure it all out but I'm sure that will be a big help!
Yeah the way to send information between Vehicle Lua and GameEngine Lua is pretty hackish but that's the only way to do it. :\ And FYI the "script_state_table" data is one frame behind so you'll be receiving the "scriptTime" from the previous frame.