Calling a server function from a client?

Hi!

Lets say I have a function on the player,and it should call another one found on the server only.

Since the server only runs on the client that hosts the game,how do I do that.

(BTW, it doesnt work on the client that has the server either).

So,simple question : How do I call a function on server from a client?

Thank you.

1 Answer

1

The function can exist on each player, but can be called only on a server. I’m not sure I understand the problem here. You can make a RPC call from a client to the server only with RPCMode.Server. See the doc HERE

I have tried doing this networkView.RPC('CheckPoints',RPCMode.Server); But it gives me an error telling me that 'CheckPoints' is not attached to the player .. It should send that to server though..

No, because it checks if everyone has the method, not only the server. But the method can be called on the server only if your code allows it to be called only on the server :). Basically, the first parameter defines a function that must exist everywhere, without checking the second parameter (which is read on runtime only).

In this case I need to create a 'blank' function everywhere, just so it never gives me that error?

No, you need to attach the same script to the server and the clients. But this method will only be called on the server because when you call it with a RPC call, you will always put RPCMode.Server as second argument.

Ok,I get it..