Author Topic: RFC question  (Read 3788 times)

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
RFC question
« on: February 18, 2013, 10:20:58 AM »
First of all sorry for stupid question Iam new to RFC and I dont understand it at all:)

In my script I have:
  1. void Start(){
  2. transform.localScale = new Vector3 (0.5f, 0.5f, 0.5f);
  3. transform.parent = cube_gen.transform.parent;
  4. }

I was tried call this by RFC like this:
  1. void Start (){
  2. TNObject test = GetComponent <TNObject>();
  3. test.Send ("Scale", Target.AllSaved, gameObject.transform);
  4. }
  5.  
  6. [RFC] void Scale (Transform test_transform){
  7. test_transform.localScale (0.5f, 0.5f, 0.5f);
  8. test_transform.parent = cube_gen.transform.parent;
  9. }

but it is not work. Can someone please give me working code or some very simple example how to use RFC?
Thanks for answer.

Suvu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: RFC question
« Reply #1 on: February 18, 2013, 10:33:53 AM »
Hey matis!

It doesn't work because you're sending a transform and then not applying it back to the gameObject,
If you just want to change the objects scale, try this instead :

  1. void Start ()
  2. {
  3.     test_transform.parent = cube_gen.transform.parent; //Set the parent if needed
  4.     if (TNManager.isHosting) // Only send the new scale if you are the host (or you could use TNManager.isThisMyObject but that needs to be checked on Awake!)
  5.     {
  6.         TNObject test = GetComponent <TNObject>();
  7.         test.Send ("SetScale", Target.AllSaved, new Vector3(0.5f, 0.5f, 0.5f));
  8.     }
  9. }
  10.  
  11. [RFC]
  12. void SetScale (Vector3 scale)
  13. {
  14.     gameObject.transform.localScale = scale; // apply the scale back to the gameObject
  15. }
  16.  

Hope that helps!
« Last Edit: February 18, 2013, 10:44:42 AM by Suvu »

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: RFC question
« Reply #2 on: February 18, 2013, 10:39:37 AM »
Hi,
thanks it is works great. Can you please show me code also for that parenting - for better understand RFC?

EDIT:
Can any one please show how to call RFC for this code?
  1. transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent
« Last Edit: February 19, 2013, 03:58:04 AM by matis »

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: RFC question
« Reply #3 on: February 19, 2013, 04:23:04 AM »
Hi,
thanks it is works great. Can you please show me code also for that parenting - for better understand RFC?

EDIT:
Can any one please show how to call RFC for this code?
  1. transform.parent = cube_gen.ter_position[cube_gen.terrain_i].transform.parent

Can't you just put that code inside an RFC, like you had it in your first example?

matis

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: RFC question
« Reply #4 on: February 19, 2013, 06:25:11 AM »
oh:) it is "work" - problem is some of objects are placed not to correct position but I will figure that out. Thanks
btw why is that working? My .Send ("SetScale", Target.AllSaved, new Vector3(0.5f, 0.5f, 0.5f)); saying just new Vector3 nothing about transform,...

one problem what I founded - client have different terrain objects as a host. terrain is created by that RFC
« Last Edit: February 19, 2013, 12:37:32 PM by matis »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC question
« Reply #5 on: February 19, 2013, 08:03:06 PM »
Simple rules to follow:
1. If you used Instantiate, change it to TNManager.Create.
2. If you called a function directly to do something and you want it to work on all clients, replace it with an RFC call.
3. Only the TNManager.isHosting client should be calling RFCs that do stuff.
4. Never modify local variables. Always do an RFC call to modify variables.

Follow these simple rules, and everything will work correctly.

To illustrate #4 in greater detail -- do not do this:
  1. transform.position = Vector3.zero; // This is wrong!
Do this instead:
  1. tno.Send("SetPosition", Target.All, Vector3.zero);
...and implement the function:
  1. [RFC] void SetPosition (Vector3 pos) { transform.position = pos; }