its possable as its under lua/ge/ge_utils ill have already tried to use it but failed as I can't get it to take a file path like filename = "D:/Program Files/steam/steamapps/common/BeamNG.drive/lua/vehicle/hydros.lua" then if I tried printing f I got nil or am i doing something wrong? :thinking emoji:
Only BeamNG.drive directory is exposed to the game engine. So try using lua/vehicle/hydros.lua path instead
Just a quick heads up, io operations can be quite slow, so try to avoid doing it every update. Glad to see you've got it working though
Yeah I'm bumping but now I'm trying to use it from ge_utils.lua with getFileSize() intend of having Code: f = io.open(filename, "r") res = f:seek("end") in the lua file so I tried using: Code: local res = obj:queueGameEngineLua('getFileSize("lua/vehicle/hydros.lua")') and Code: obj:queueGameEngineLua('res = getFileSize("lua/vehicle/hydros.lua")') but whatever I tried I couldn't get a return value
You can't get return values from queued commands to another lua vm. When you really need to you can get values between vlua and gelua by queuing a ge command from vlua, that will itself queue a vlua command with the return value as a parameter. But your simplest option here is to take that getFileSize function from ge_utils.lua and copy it into a vlua script (ex: /lua/vehicle/extensions/myutils.lua) like this: Code: local M = {} local function getFileSize(filename) local res = -1 local f = io.open(filename, "r") if f == nil then return res end res = f:seek("end") f:close() return res end M.getFileSize = getFileSize return M Then from a vlua script you can do this: Code: local utils = require("extensions/myutils") local size = utils.getFileSize("file path")
BUMP! I found a way to get the file size from the game engine and return it to the vehicle Lua, and it's this: Code: obj:queueGameEngineLua("be:getPlayerVehicle(0):queueLuaCommand('FileSize(' .. getFileSize(\"lua/vehicle/hydros.lua\") .. ')')") function FileSize(FS) print(FS) end Yeah, it was that simple, or I guess complex, so hopefully this can help someone else