Jump to content

[Help] invokeClientFunction


Macro

Recommended Posts

Hi,

I'm currently working on developing a mod that will need to communicate between both the server and the client.  Reading into the code it seems the intended functions for this are the invokeClientFunction and the invokeServerFunctions, but I have an issue where when they are called nothing happens.  I've been developing in a Single Player game since it seems these games are just dedicated servers that shutdown upon the player leaving and that have no connections others to latch onto.  I'll post the test code that exist as a modification of the tradeoverview.lua file, the results are posted below as well

-- Test Code
function test(response)
	if response then
		print(response)
		return
	end

	print("-- -- -- Test Started -- -- --")

	test_request(test)
end


function test_request()
	print("[test_request]")
	print("onClient? " .. tostring(onClient()))
	print("onServer? " .. tostring(onServer()))
	print("Calling Player: " .. Player().index)
	callingPlayer = Player().index

	if onClient() then
		print("[test_request]: Client")

		invokeServerFunction("test_request")
	end

	print("[test_request]: Server ")

	local code = [[
		package.path = package.path .. ";data/scripts/lib/?.lua"
		package.path = package.path .. ";data/scripts/?.lua"

		function run(callingPlayer)
			print("[test_requset] Async")
			return "Hello, World", callingPlayer
		end
	]]
	async("test_recieve", code, callingPlayer)
end

function test_recieve(response, callingPlayer)
	print("[test_recieve]")
	print("onClient? " .. tostring(onClient()))
	print("onServer? " .. tostring(onServer()))
	print(response)
	print(callingPlayer)

	if onServer() then
		local player = Player(callingPlayer)
		print(tostring(player))
		if player then
			invokeClientFunction(player, "test_recieve", response)
		end
	else
		print(response)
	end
end

image.png.0dda07aae0bcd4103ac38c205b348a71.png

 

It seems the code does not start off within the client, but also cannot reach the client for the call to be invoked?  Can anyone explain what is happening?  Also, if you know about where calls originate I would appreciate it since I do not understand why the initial onSectorChanged call seems to already assume that I'm working on the sever both here and with the /command function I built.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...