Hello, I´m messing around with a custom camera mode. The camera script is running in the GameEngine Environment and I want to get the inputs-stream which is only available in the VehicleLua Environment. Is there a fancy function which does allow what I want to do? Or is there a dirty workaround? Btw I also thought about a workaround over Javascript, but the problem there is, that the streams only gets 15-30 ups (updates per second ) and the main reason for switching to lua was the higher update frequency. Greets
The following solution is most-probably the worst and least elegant solution ever but... You are looking for steering value, right? Have you tried something like this: Code: local player = 0 local veh = be:getPlayerVehicle(player) veh:queueLuaCommand('dump(electrics.values.steering)') Edit: Wait... you cannot store the result in a field. The queueLuaCommand returns null since it gets executed next frame. So this won't work (or rather x will contain null): Code: local x = veh:queueLuaCommand('dump(electrics.values.steering)')
Yep Yep, but I tried it with "veh = be:getObjectByID(0)" I tested your code in the Update method and like you said x returns nil :/
Ok here you go: Code: be:getPlayerVehicle(0):queueLuaCommand(string.format('obj:queueGameEngineLua(string.format(%q, serialize(electrics.values.steering)))', 'dump(unserialize(%q))')) This is how it works. Back and forth..! Keep in mind that it will have a two-frame-delay because of that.
Ok, the code works like the codes above. But how I can access the variable in my code? Code: local x = be:getPlayerVehicle(0):queueLuaCommand(string.format('obj:queueGameEngineLua(string.format(%q, serialize(electrics.values.steering)))', 'dump(unserialize(%q))')) dump(x) --return: nil
Works here. May it be that x is not in the same scope. May it be that it's just local for your function?! Code: local M = {} local x local function test() local player = 0 local veh = be:getPlayerVehicle(player) if not veh then return nil end x = be:getPlayerVehicle(0):queueLuaCommand(string.format('obj:queueGameEngineLua(string.format(%q, serialize(electrics.values.steering)))', 'dump(unserialize(%q))')) print(x) end M.test = test return M Calling the test function from this lua module prints x. Edit: For testing purposes you could get rid of the local to create a global variable. Code: x = be:getPlayerVehicle(0):queueLuaCommand(string.format('obj:queueGameEngineLua(string.format(%q, serialize(electrics.values.steering)))', 'dump(unserialize(%q))')) print(x)
This is how it works: Code: local M = {} local function test() local player = 0 local veh = be:getPlayerVehicle(player) if not veh then return nil end be:getPlayerVehicle(0):queueLuaCommand(string.format('obj:queueGameEngineLua(string.format(%q, serialize(electrics.values.steering)))', 'vlua.test2(unserialize(%q))')) end local function test2(steering) print(steering) end M.test2 = test2 M.test = test return M