HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: (RESOLVED)Calling a client method/function from the server  (Read 84 times)

Joseph-B

  • General Accounts
  • *
  • Posts: 5
    • View Profile

Hello,

I am having trouble calling functions/methods in client scripts from the server.

I have tried a few different ways:

1: MiscUtils:ServerToClientNode
Code: [Select]
wallRef as Noderef of class UOS_SeekerDoorController = CreateNodeFromClass("UOS_SeekerDoorController")
clientWallRef as NodeRef = MiscUtils:ServerToClientNode(wallRef)
clientWallRef.openDoor()

2: call clientReplicas
Code: [Select]
wallRef as NodeRef of Class UOS_SeekerDoorController = CreateNodeFromClass("UOS_SeekerDoorController") //Get a nodeRef (pointer) to the object with this ID
call clientReplicas myNodeRef.wallRef()

3: call client account ClientScript:Function
Code: [Select]
method GUI(account as NodeRef)
    println("Server sided method has been called.")

    makeRemoteCall(account)

    println("Finished calling remote client method.")
.

public function makeRemoteCall(account as NodeRef)
    println("Attempting to make remote call...")
    call client account UOS_GUIScript:Test()
.

I can't find how to call a method/function on a client script/class from the server - if anybody has this information or could point me in the right direction it would be greatly appreciated! :D

Many Thanks!

Joseph
« Last Edit: Mar 27, 17, 06:10:47 AM by Joseph-B »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1051
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Calling a client method/function from the server
« Reply #1 on: Mar 20, 17, 01:28:04 PM »

There are a few ways of calling a client function from script from server. The "call client" are key words, which needs the account to know which client.

The direct way, calls a function using the script name, then the function name, and parameters.
example:
  call client account FooClassMethods:DoFoo()  // where DoFoo is a function

There is also the class method way

  call client account FooClass.DoFoo()        // where DoFoo is a method



On the client side the key word is "remote", in order to receive the server call. On the client side, the method would be:

 remote method DoFoo()

or function

  remote function DoFoo()
Logged
Heroes and Villains Lead programmer/scripter

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1359
    • View Profile
    • Forever Interactive, Inc.
Re: Calling a client method/function from the server
« Reply #2 on: Mar 20, 17, 02:19:36 PM »

More details here:
http://hewiki.heroengine.com/wiki/RemoteCall2

If a node is replicated to a client then it is defined both on the server and client, and has the same node ID on both sides.

"call client" will be for calling to either a single specific client ID, or a list of client IDs.  If node is only defined on the remote side and not on the calling side, you cannot simply assign the node ID to a nodeRef variable to make the call. That is because when you assign to a nodeRef and it cannot find that node locally, the nodeRef becomes None and calling a method with that results in a script error. What you can do in that case (I think) is assign the ID to a variable of type ID instead of nodeRef and then call the method on that variable.

"call clientreplicas" is handy when you know the node is replicated to 0 or more clients and you just want the call going to all clients which currently have it without having to specify exactly which clients those are.

Besides calling a method on a node, you may call a function in a script by specifying scriptName:FunctionName().

You can remote call to a method of a system node by using the % symbol in place of the $ symbol when referencing the system node name, e.g.

call client someClientID %SystemNodeName.methodName()

The "%" means that you are referencing a system node on the other side as opposed to a system node on the calling side. That is because both sides could have a system node with a given name, but not necessarily be the same node ID.



Whether it be a function or method:
  • Client ones to be called from the server must be labeled "remote".
  • Server ones called from a client must be labeled "untrusted" (which is also a visual reminder that you should confirm the validity of the request to cut down on cheating).
  • Server ones called from other server areas must be labeled "remote".
« Last Edit: Mar 20, 17, 02:34:20 PM by FI-ScottZ »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Joseph-B

  • General Accounts
  • *
  • Posts: 5
    • View Profile
Re: Calling a client method/function from the server
« Reply #3 on: Mar 27, 17, 06:10:30 AM »

Thank you very much!

Very in-depth explanation, I was able to solve the problem with your solution.
Logged