Author Topic: [Solved] Exception has been thrown by the target of an invocation.  (Read 8508 times)

ckrin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
hey,

i searchd the forum first, but didnt get my mistake.
i get the error in my script. i have a script called applyCharCustom.js wich handles the look of the players avatar since i got multiple characters and skins and weapons available.
in start function i send all the players the visual style of the new player. everytime a new player joins everyone know how he should look. works like a charm.

  1. function Start(){
  2. tno=GetComponent(TNObject);
  3. if(tno.isMine)
  4. {
  5.         race=PlayerPrefs.GetInt("race");
  6.         skin=PlayerPrefs.GetInt("skin");
  7.         weaponHolder=PlayerPrefs.GetInt("weaponHolder");
  8.        
  9.         tno.Send("raceSwitch",Target.All,race);
  10.         tno.Send("weaponSwitch",Target.All,weaponHolder);
  11.         tno.Send("skinSwitch",Target.All,skin);
  12.         //raceSwitch();
  13.         //weaponSwitch();
  14.         //skinSwitch();
  15. }
  16. }
  17.  

problem is the code below. new players doesnt know how earlyr connected players look like, so my idea was to just use the OnNetworkPlayerJoin function to tell the new player how the others should look like. on this call i get the error. it works and the visual style is set correct, but after the error, the new player doesnt see animations on the others at all. :/

  1. function OnNetworkPlayerJoin(p:Player){
  2.  
  3.         tno.Send("raceSwitch",p,race);
  4.         tno.Send("weaponSwitch",p,weaponHolder);
  5.         tno.Send("skinSwitch",p,skin);
  6.  
  7. }


any idea?
« Last Edit: October 20, 2013, 09:20:45 AM by ckrin »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Exception has been thrown by the target of an invocation.
« Reply #1 on: October 19, 2013, 08:53:19 PM »
Why don't you send them using Target.OthersSaved? Then you don't need to do it again in OnNetworkPlayerJoin as it will be done automatically.

ckrin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Exception has been thrown by the target of an invocation.
« Reply #2 on: October 19, 2013, 09:14:23 PM »
just tried it, caused the error as well :/
how could this be? i mean two lines above i use the same calls in start function.

ckrin

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Exception has been thrown by the target of an invocation.
« Reply #3 on: October 20, 2013, 09:20:13 AM »
works now with AllSaved, thanks alot!

seems like i forgot to set var tno:TNObject; public :/