Author Topic: UICheckbox multiplayer TNObject/RFC updates  (Read 3398 times)

outerringz

  • Guest
UICheckbox multiplayer TNObject/RFC updates
« on: June 05, 2013, 10:55:14 AM »
I've been trying, without success, to get NGUI components to update across the network in a multiplayer game.

For my testing, I've been using a UICheckbox and trying to get the checkbox.isChecked status to update for two players connected via networking.

I have tried placing TNObject components on the UICheckbox. I've also tried placing my OnClick() code in an RFC method and calling that method from the OnClick().

  1. void OnClick()
  2. {
  3.         TNObject tno = GetComponent<TNObject>();
  4.         tno.Send("PlayerSelected", Target.All, null);
  5.  
  6.         //networkView.RPC("PlayerSelected", RPCMode.All);
  7. }
  8.  
  9. [RFC]
  10. void PlayerSelected()
  11. {
  12.         if (checkbox.isChecked)
  13.         {
  14.                 checkbox.isChecked = true;
  15.                 gameSetupScript.playerHost = playerClass;
  16.         }
  17.         else
  18.         {
  19.                 checkbox.isChecked = false;
  20.                 gameSetupScript.playerHost = PlayerClass.None;
  21.         }
  22. }
  23.  

Any help anyone can offer is appreciated.

SketchWork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #1 on: June 05, 2013, 12:09:24 PM »
The logic in your PlayerSelected isn't quite right.

  1. [RFC]
  2. void PlayerSelected()
  3. {
  4.     if (!checkbox.isChecked)   // <---- this line make "if not checked" like this
  5.     {
  6.         checkbox.isChecked = true;
  7.         gameSetupScript.playerHost = playerClass;
  8.     }
  9.     else
  10.     {
  11.         checkbox.isChecked = false;
  12.         gameSetupScript.playerHost = PlayerClass.None;
  13.     }
  14. }

Justin

outerringz

  • Guest
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #2 on: June 05, 2013, 12:25:01 PM »
Thanks, but the NGUI UICheckbox script already tracks its [is checked] status, I'm only trying to report it's status changes over the network.

outerringz

  • Guest
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #3 on: June 05, 2013, 03:34:01 PM »
I've also tried to sync the checkbox status changes using TNAutoSync with a UICheckbox isChecked property, but that doesn't seem to work either.

SketchWork

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #4 on: June 06, 2013, 04:34:21 AM »
The code in your example doesn't make any sense.  (If checked = true then checked = true)

Why not pass the checked boolean value as a parameter?

  1. void OnClick()
  2. {
  3.     TNObject tno = GetComponent<TNObject>();
  4.     tno.Send("PlayerSelected", Target.All, checkbox.isChecked);
  5.  
  6.     //networkView.RPC("PlayerSelected", RPCMode.All);
  7. }
  8.  
  9. [RFC]
  10. void PlayerSelected(bool bIsChecked)
  11. {
  12.     if (bIsChecked)
  13.     {
  14.         checkbox.isChecked = true;
  15.         gameSetupScript.playerHost = playerClass;
  16.     }
  17.     else
  18.     {
  19.         checkbox.isChecked = false;
  20.         gameSetupScript.playerHost = PlayerClass.None;
  21.     }
  22. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #5 on: June 06, 2013, 07:15:32 AM »
What SketchWork said. :)

outerringz

  • Guest
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #6 on: June 07, 2013, 09:54:16 PM »
Thanks SketchWork, this was part of my problem. It didn't work in my current project but it did in a test project, so I must have some other issue that I'll work out. Appreciate the help!


Arenmook, I originally posted this question in the NGUI forum where you made no attempt to assist but only offered that I could purchase TNet as a solution. I bought it, attempted a TNet version of the same problem I was trying to solve and ran into similar problems. I re-posted the question to the TNet forum and your contribution to assist is "What he said." Please, if you're going to take the time to respond in the future, maybe offer something useful like an explanation of why Sketchwork's suggestion should solve my problem. I understand what I was doing wrong now, but "what he said" offers zero value to the community. Why bother?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICheckbox multiplayer TNObject/RFC updates
« Reply #7 on: June 07, 2013, 09:58:14 PM »
Sure, sorry, didn't mean to come off short -- I was merely trying to convey that SketchWork provided a very detailed and thorough answer -- moreso than I could have given actually.