celludriel Posted June 14, 2017 Share Posted June 14, 2017 I got following class package.path = package.path .. ";data/scripts/lib/?.lua" package.path = package.path .. ";data/scripts/empirebuilder/?.lua" package.path = package.path .. ";data/scripts/empirebuilder/util/?.lua" package.path = package.path .. ";data/scripts/player/?.lua" require ("EmpireBuilderUtil") TaskManager = require ("TaskManager") local EmpireBuilderGameManager = {} EmpireBuilderGameManager.__index = EmpireBuilderGameManager local function new() logDebug("creating EmpireBuilderGameManager") local obj = setmetatable({}, EmpireBuilderGameManager) local taskManager = TaskManager() obj.taskManager = taskManager EmpireBuilderContext["GameManager"] = obj return obj end function EmpireBuilderGameManager:registerCallbacks(player) logDebug("begin TaskManager:registerCallbacks") player:registerCallback("onSectorEntered", "attachEmpireInformationWindowOnSectorChange") player:registerCallback("onShipChanged", "attachEmpireInformationWindowOnShipChange") logDebug("end TaskManager:registerCallbacks") end function attachEmpireInformationWindowOnSectorChange() logDebug("begin TaskManager:attachEmpireInformationWindowOnSectorChange") end function attachEmpireInformationWindowOnShipChange(playerIndex, craftIndex) logDebug("begin TaskManager:attachEmpireInformationWindowOnShipChange", playerIndex, " + ", craftIndex) local player = Player(playerIndex) logDebug("player ", player) invokeClientFunction(player, "addEmpireInformationWindowToShip") logDebug("end invoke addEmpireInformationWindowToShip") end function addEmpireInformationWindowToShip() logDebug("addEmpireInformationWindowToShip") local ship = Player().craft if not ship.isDrone then if not ship:hasScript("data/scripts/empirebuilder/ui/EmpireInformationWindow.lua") then ship:addScriptOnce("data/scripts/empirebuilder/ui/EmpireInformationWindow.lua") end end end function EmpireBuilderGameManager:executeGameLoop() logDebug("begin executeGameLoop") self.taskManager:executeTaskManager() logDebug("end executeGameLoop") end return setmetatable({new = new}, {__call = function(_, ...) return new(...) end}) There is an instance of it running serverside, but I want to add a script to the ship a player is flying after he changed ships. If you look at the method attachEmpireInformationWindowOnShipChange you see I do a clientInvokeFunction, but it never triggers and there is no error. not in server log or client log. However I do find logDebug("end invoke addEmpireInformationWindowToShip") in the server log, so the method has been triggered somehow, just never run. Without any logging I have no idea why. Except maybe that the instance of EmpireBuilderGameManager isn't know at client side ? Is there a better way for the server to call client methods ? Link to comment Share on other sites More sharing options...
celludriel Posted June 18, 2017 Author Share Posted June 18, 2017 I've learned that you can only do these kind of things on scripts attached to objects that exist client and server side at the same time with the same unique id. You can't just instance a class and expect it to be able to do this kind of communication. For future reference Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now