Search Unity

  1. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  2. Unity 2017.1 is now released.
    Dismiss Notice
  3. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  4. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

Problem managing quests progress

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

  1. skattigat


    Mar 13, 2013
    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):
    2. myPlayer.GetComponent <PlayerQuestManager> () .GetCurrentQuest ()
    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


    Jan 24, 2013
    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


    Mar 13, 2013
    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?