Forum begins after the advertisement:


[Part 12] Withering of Plant Problem

Home Forums Video Game Tutorial Series Creating a Farming RPG in Unity [Part 12] Withering of Plant Problem

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #17156
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    partpaI encountered a problem regarding the Wither status of the Plant.

    Scenario: -I plant, watered and leave the planting area scene -Plant health goes up -Plant health goes down when not watered (Sample 15 Plant Health) -Return to the Planting Area scene -Leave the Planting Area scene -Plant Health is 2,500

    View post on imgur.com
    #17157
    Jonathan Teo
    Level 18
    Moderator
    Helpful?
    Up
    1
    ::

    Did the Debug message come from GameStateManager?

      1 anonymous person
    has upvoted this post.
    #17160
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    Yes, from the UpdateFarmState

    #17161
    Jonathan Teo
    Level 18
    Moderator
    Helpful?
    Up
    1
    ::

    The problem happens when you load into the scene. Try adding debug logs on the functions that get called, like

    public void ImportCropData(List<CropSaveState> cropDatasetToLoad)
    {
        Debug.Log("ImportCropData called");
        cropData = cropDatasetToLoad;
        foreach (CropSaveState cropSave in cropDatasetToLoad)
        {
            Debug.Log($"Importing crop - Health: {cropSave.health}");
            //... rest of the code ...
    
        }
    }
      1 anonymous person
    has upvoted this post.
    #17165
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    Sorry if this may sound rude but I don’t know where to place the code

    #17166
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    The Bug appears when the CropStatus is now on Seedling

    #17167
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    This is my UpdateFarmState

    void UpdateFarmState(GameTimeStamp timestamp)
    {
        //Updates the Land and Crop Save states as long as the player is outside of the PlantingArea scene
        if(SceneTransitionManager.Instance.currentLocation != SceneTransitionManager.Location.PlantingArea)
        {
            if (SoilManager.urbanFarmData == null)
            {
                return;
            }
    
            List<SoilSaveState> soilData = SoilManager.urbanFarmData.Item1;
            List<CropSaveState> cropData = SoilManager.urbanFarmData.Item2;
    
            //If there are no crops planted on a certain soil, don't need to update
            if(cropData.Count == 0)
            {
                return;
            }
    
            for(int i = 0; i < cropData.Count; i++)
            {
                CropSaveState crop = cropData[i];
                SoilSaveState soil = soilData[crop.soilID];
    
                //Check if the crop is already wilted
                if(crop.cropState == NewCropBehaviour.CropState.Wilted)
                {
                    continue;
                }
    
                //Update the Soil's state
                soil.ClockUpdate(timestamp);
    
                //Update the crop's state based on the soil state
                if(soil.soilStatus == PottingSoil.SoilStatus.Watered)
                {
                    crop.Grow();
                }
                else if(crop.cropState != NewCropBehaviour.CropState.Seed)
                {
                    crop.Wither();
                }
    
                //Update the element in the array
                cropData[i] = crop;
                soilData[crop.soilID] = soil;
            }
    
            SoilManager.urbanFarmData.Item2.ForEach((CropSaveState crop) =>
            {
                Debug.LogWarning(crop.seedToGrow + "\n Health: " + crop.health + "\n Growth: " + crop.growth + "\n State: " + crop.cropState.ToString());
            });
        }
    }
    #17172
    Jonathan Teo
    Level 18
    Moderator
    Helpful?
    Up
    1
    ::

    I mean the ImportCropData in LandManager

    //Load over the static farmData onto the Instance's cropData
    public void ImportCropData(List<CropSaveState> cropDatasetToLoad)
    {
        cropData = cropDatasetToLoad;
        foreach (CropSaveState cropSave in cropDatasetToLoad)
        {
            Debug.Log($"Importing crop - Health before: {cropSave.health}");
            //Access the land
            Land landToPlant = landPlots[cropSave.landID];
            //Spawn the crop
            CropBehaviour cropToPlant = landToPlant.SpawnCrop();
            Debug.Log(cropToPlant.gameObject);
            //Load in the data
            SeedData seedToGrow = (SeedData)InventoryManager.Instance.GetItemFromString(cropSave.seedToGrow);
            cropToPlant.LoadCrop(cropSave.landID, seedToGrow, cropSave.cropState, cropSave.growth, cropSave.health);
        }
    
    }
      1 anonymous person
    has upvoted this post.
    #17173
    Jhan Khendrick Perez
    Level 5
    Participant
    Helpful?
    Up
    0
    ::

    This is the Result

    Might be wondering why the Soil changed to Green, it just turn into Weed state and not watered

    View post on imgur.com
    #17177
    Jonathan Teo
    Level 18
    Moderator
    Helpful?
    Up
    0
    ::

    Something is increasing the health in between. Where’s the debug logs from the update farm state? In Visual Studio, right click SoilManager.urbanFarmData.Item2 on “Item2”, select Find all references to it, and check what is being updated. If you can’t find the part of your code that is increasing the value, add a debug log everywhere it is used.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: