1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

Problem managing quests progress

Discussion in 'Multiplayer Networking' started by skattigat, Mar 20, 2017.

  1. skattigat

    skattigat

    Joined:
    Mar 13, 2013
    Posts:
    10
    Hello to all.

    I'm working on a simple system Quest for a multiplayer game.
    Each player has its own "quest log" with their progress.

    On a certain quest the player must kill a few enemies.
    To manage the killings I have added a script called "QuestEnemy" to prefab of the enemy.

    When the enemy is killed I call the component "PlayerQuestManager" (also a script, but attached to the player) to see if the player is on this quest and what is the state of play:

    Code (CSharp):
    1. public void Killed (int PlayerNetID) {
    2.     myPlayer = PhotonView.Find (PlayerNetID).gameObject;
    3.     if (myPlayer.GetComponent<PlayerQuestManager> ().GetCurrentQuest () != QuestNum) {
    4.         // player does not have this quest
    5.         return;
    6.     }
    7.     if (myPlayer.GetComponent<PlayerQuestManager> ().CurrentQuestCompleted ()) {
    8.         // player has already completed this quest
    9.         return;
    10.     }
    11.     // OK: increment num kills for this quest
    12.     myPlayer.GetComponent<PlayerQuestManager>().QuestKill(QuestKillN);
    13. }
    My problem is in this code:

    Code (CSharp):
    1.  
    2. myPlayer.GetComponent <PlayerQuestManager> () .GetCurrentQuest ()
    3.  
    It always returns "-1", which means that the player is not on that quest.
    However I am sure that the player is on the quest.

    If I call the same function in PlayerQuestManager logging the current quest number I see the correct number.

    Can you help me figure out what I'm doing wrong?
     
  2. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    109
    I feel like I might be stating the obvious here, but it sounds like you need to do some debugging... some suggestions:
    • look at the code of PlayerQuestManage.GetCurrentQuest, and look at the potential reasons why it might return -1
    • make a note of all of the possible reasons (there will likely be quite a few), and debug each possibility. For example, it may be that the PlayerNetID that you are providing is invalid or it may be the questNum is invalid. Look at the values of all of the variables that you are using in the above process and make sure all values are what you expect them to be. Chances are that's where your issue is.
    There are quite a few documents/tutorials by unity explaining different ways to debug your code. The most accessible approach is to use Debug.Log to output things to the editor console, but there are more detailed approaches if that doesn't help. Ultimately though, if code doesn't do what you expect it to do, take the chance to brush up on your debugging skills as they are just as important as everything else :)

    Good luck!
     
  3. skattigat

    skattigat

    Joined:
    Mar 13, 2013
    Posts:
    10
    Hello and thanks for the reply.

    I'm running several tests using a lot of debugging informations (Debug.Log()).

    From what I understand the problem is that the function

    Code (CSharp):
    1. GetComponent<QuestEnemy> ().Killed (PlayerNetID);
    It is performed only on MasterClient, who does not know the status of the players progress.

    A value of -1 is returned because this is the default value assigned to the variable CurrentQuest when the player is created the first time.

    I'm doing it the wrong way?