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

Author Topic: [RESOLVED] Client to Server updating a field  (Read 1559 times)

feredfn

  • General Accounts
  • *
  • Posts: 154
    • View Profile
[RESOLVED] Client to Server updating a field
« on: Dec 20, 13, 07:25:55 AM »

Hello there,

i have 2 classes with some fields on both client and server
my fields have reverse and callback options = yes , and has field destinations on both server and client
my class also has the destination class for both client and server and the R checkbox of the fields are also checked
from server to client it works , and its also calling _OnReplicationFieldUpdated on the client ..


but if i change the fields via client , how can server notice this change?

( better example : i have a slider which controls the strength stat of the character, i want to do some calculations on server if the slider has changed )
« Last Edit: Dec 22, 13, 12:24:00 AM by feredfn »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1160
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Client to Server updating a field
« Reply #1 on: Dec 20, 13, 01:44:42 PM »

Inside the function on the client side, to evaluate the location of the slider, when the value actually changes from its starting position, then send a message to the server letting it know.

method _onSliderChangeValue()

  when silder.name
     is "Strength"
        if newValue <> originalValue
           Call server account ....
        .
     .
   .
.
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Client to Server updating a field
« Reply #2 on: Dec 20, 13, 10:07:51 PM »

feredfn,

It sounds like you are asking about reverse replication.  Provided you have set it up right, as it sounds like you have, then the callback works the same way: in the server-side class methods script of the class with the reverse replicated field you would define

Code: [Select]
shared function _OnReplicationFieldUpdated( replicatedNode as NodeRef, fieldName as String)

.

to act when the field changes value.

One more thing to make reverse replication work which is easy to miss is done on the server side:
For each player account that will be reverse replicating you need to get the _ReplicationGroup nodeRef that is responsible for replicating the node with the field(s) in question and on that group node set the _replicationNodesAndReverseClient field, something like this:

group._replicationNodesAndReverseClient[nodeRefWithFields] = playerAccountNode

There are some convenience methods which wrap some of that (such as _SetReverseReplicationForNode()), but we found we liked having more direct control and so work on the _replicationNodesAndReverseClient field directly.
See here for more details:
http://hewiki.heroengine.com/wiki/Replication_Script_Interface#Replication_Group_Fields

I hope that helps.
« Last Edit: Dec 20, 13, 10:15:16 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

feredfn

  • General Accounts
  • *
  • Posts: 154
    • View Profile
Re: Client to Server updating a field
« Reply #3 on: Dec 21, 13, 12:42:41 AM »

To Thazager,

Thx mate , i also wrote such code at the moment because i wasn't manage to work with the reverse technique , but i just think using reverse technique of replication is what i want , because i want to do some calculations and visual changes depending on field updating on some class methods .. plus somehow i think its a little faster than call server ...

To ScottZarnke , 
Thx mate, seems that i will be able to fix the problem with ur help , i will work on it today , ...


Cheers
Logged

feredfn

  • General Accounts
  • *
  • Posts: 154
    • View Profile
Re: Client to Server updating a field
« Reply #4 on: Dec 21, 13, 07:54:49 AM »

Well it worked , Thank you...
But i have a question, seems that every time i change the area , i must add the node with those fields to the account replication group again to make reverse call back working..

is this a normal situation? or i missed something?
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: Client to Server updating a field
« Reply #5 on: Dec 21, 13, 12:13:49 PM »

Well it worked , Thank you...
But i have a question, seems that every time i change the area , i must add the node with those fields to the account replication group again to make reverse call back working..

is this a normal situation? or i missed something?

Yes that is normal.  Since server-side nodes exist in exactly one area instance GOM at-a-time, when you change areas, the node you were referring to does not exist in the new area instance.

There are workarounds such as replicating a proxy of the node to the other instance*, but that may be more work than it is worth depending on how you are using it.

*That is how the same single account and character nodes can be continually referenced as you change areas: server-to-server replication.
« Last Edit: Dec 21, 13, 12:15:21 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.