Good news! To provide faster support and grow the community, we'll be changing the forum to "Read Only" and turn to Discord instead for support.
Join here: https://discord.gg/zjNj5zZ

How to use Trigger Callbacks

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

How to use Trigger Callbacks

Postby Adressa » Thu Aug 31, 2017 2:12 am

Hi, I've been using Inventory Pro for a while and it's super useful.
I'm having a problem understanding how to use callbacks though. I want my player to be able to trigger an object (not window nor item, just a gameobject) and execute the script attached to it.
But I dont understand how to use the "callbacks", triggers gave me a really hard time with this asset.

So what I did was I added a "Trigger" script and my "DoThis" script. And this is the "DoThis" script:

Code: Select all

using UnityEngine;
using Devdog.General;

public class DoThis : MonoBehaviour, ITriggerCallbacks
{

    public void OnTriggerUsed(Player player)
    {
        Debug.Log("TRIGGERED");
    }

    public void OnTriggerUnUsed(Player player)
    {
        // The trigger has een unused
    }
}

However, I get a code error for Used and UnUsed.

Code: Select all

Assets/Scripts/DoThis.cs(4,14): error CS0738: `DoThis' does not implement interface member `Devdog.General.ITriggerCallbacks.OnTriggerUsed(Devdog.General.Player)' and the best implementing candidate `DoThis.OnTriggerUsed(Devdog.General.Player)' return type `void' does not match interface member return type `bool'

I'm sure I'm just doing something wrong, but I really didn't find any answer. What am I doing wrong?

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: How to use Trigger Callbacks

Postby PeterBibinin » Fri Sep 01, 2017 5:34 am

IP has documentation errors. And it's not the first :)

OnTriggerUser and OnTriggerUnUsed is bool not void ;)

Should be:

Code: Select all

public bool OnTriggerUsed(Player player)
    {
        Debug.Log("TRIGGERED");
       
        //and I think should:
        return false;
    }

    public bool OnTriggerUnUsed(Player player)
    {
        // The trigger has een unused
       
                //and I think should:
        return false;
    }
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: How to use Trigger Callbacks

Postby Adressa » Fri Sep 01, 2017 8:02 am

It doesn't work, I think the problem is in the Trigger I'm applying to the object. It's not the first time something doesn't work as intended. Another problem I have that is way bigger to me now is that if I add a TriggerRangeHandler to have individually different ranges in Objects, the trigger doesn't even activate.

So I'll just code my own triggers for things that aren't inventories. Tho do you have any idea why adding a TriggerRangeHandler doesn't work? I have 0 errors and every other thing is working just fine.

JeffG
Posts: 4
Joined: Tue Jul 11, 2017 6:23 pm

Re: How to use Trigger Callbacks

Postby JeffG » Sat Sep 02, 2017 12:56 am

You are probably bumping into the bug I found

See

viewtopic.php?f=4&t=3103

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: How to use Trigger Callbacks

Postby Adressa » Tue Sep 05, 2017 9:12 am

I don't know if the documentation change or something but I got it working.

Code: Select all

using UnityEngine;
using Devdog.General;
using Devdog.InventoryPro;

public class RestAtWell : MonoBehaviour, ITriggerCallbacks
{
    public InventoryPlayer myPlayer;
    public string lastcheck;

   public void OnTriggerUsed(Player player)
    {
       ES2.Save(lastcheck, "LASTCHECK.txt");
       Restore();
       GameManager.SaveGame();
    }

    public void OnTriggerUnUsed(Player player)
    {
        // The trigger has een unused
    }

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

    bool ITriggerCallbacks.OnTriggerUnUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

    public void Restore()
    {
        var health = myPlayer.stats.Get("----", "Health");
        var shield = myPlayer.stats.Get("----", "Shield");
        var energy = myPlayer.stats.Get("----", "Energy");

        health.ChangeCurrentValueRaw(health.currentMaxValue);
        shield.ChangeCurrentValueRaw(shield.currentMaxValue);
        energy.ChangeCurrentValueRaw(energy.currentMaxValue);

    }
}


Tho Visual Basic showed me an error at "ITriggerCallbacks":

Code: Select all

public class RestAtWell : MonoBehaviour, ITriggerCallbacks

And the fix was adding:

Code: Select all

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

    bool ITriggerCallbacks.OnTriggerUnUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

(Visual added it automatically as a suggestion)

So now I think I have to make a "public Player player;", I think that makes sure only I can trigger.
And I suppose I don't have to care about the bools added? I'm not even sure what they do.

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: How to use Trigger Callbacks

Postby Adressa » Tue Sep 05, 2017 9:17 am

EDIT: Okay it doesn't work anymore for some reason and with the exact code of "RestAtWell" it says this.
NotImplementedException: The requested feature is not implemented.
RestAtWell.Devdog.General.ITriggerCallbacks.OnTriggerUsed (Devdog.General.Player player) (at Assets/Scripts/RestAtWell.cs:25)
Devdog.General.TriggerBase.NotifyTriggerUsed (Devdog.General.Player player) (at Assets/Devdog/General/Triggers/TriggerBase.cs:198)
Devdog.General.Trigger.DoUse (Devdog.General.Player player) (at Assets/Devdog/General/Triggers/Trigger.cs:152)
Devdog.General.Trigger.Use (Devdog.General.Player player) (at Assets/Devdog/General/Triggers/Trigger.cs:137)
Devdog.General.TriggerBase.Toggle (Devdog.General.Player player) (at Assets/Devdog/General/Triggers/TriggerBase.cs:90)
Devdog.General.TriggerBase.Toggle () (at Assets/Devdog/General/Triggers/TriggerBase.cs:80)
Devdog.General.TriggerInputHandlerBase.Use () (at Assets/Devdog/General/Triggers/TriggerInputHandlerBase.cs:54)
Devdog.General.PlayerTriggerHandlerBase`1[T].Update () (at Assets/Devdog/General/Player/PlayerTriggerHandlerBase.cs:69)


It basically does this lines:

Code: Select all

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

But if I remove them then theres the error at ITriggerCallbacks, I have no idea what to do

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: How to use Trigger Callbacks

Postby PeterBibinin » Tue Sep 05, 2017 6:45 pm

Code: Select all

bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }


In this form you write error.

Code: Select all

bool OnTriggerUsed(Player player)
    {
        // what to do if used?
       
    }


No need ITriggerCallbacks.

Same in OnTriggerUnUsed(Player player)
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: How to use Trigger Callbacks

Postby Adressa » Wed Sep 06, 2017 1:48 am

It doesn't do anything. I just want the object to do it's script when I trigger it, I don't think a bool is what I need, also the "throw new System.NotImplementedException();" is not something I need, it's created by Visual Studio as a solution because ITriggerCalbacks on the top shows an error.

Right now I have:

Code: Select all

public class RestAtWell : MonoBehaviour, ITriggerCallbacks
{

    void OnTriggerUsed(Player player)
    {
        DO THINGS
    }

    void OnTriggerUnUsed(Player player)
    {
        // The trigger has een unused
    }

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

    bool ITriggerCallbacks.OnTriggerUnUsed(Player player)
    {
        throw new System.NotImplementedException();
    }
    }


And there's an error for Used and one for UnUsed each time I try to trigger in runtime:
NotImplementedException: The requested feature is not implemented.
RestAtWell.Devdog.General.ITriggerCallbacks.OnTriggerUsed (Devdog.General.Player player)
Devdog.General.TriggerBase.NotifyTriggerUsed (Devdog.General.Player player)
Devdog.General.Trigger.DoUse (Devdog.General.Player player)
Devdog.General.Trigger.Use (Devdog.General.Player player)
Devdog.General.TriggerBase.Toggle (Devdog.General.Player player)
Devdog.General.TriggerBase.Toggle ()
Devdog.General.TriggerInputHandlerBase.Use ()
Devdog.General.PlayerTriggerHandlerBase`1[T].Update ()

User avatar
PeterBibinin
Posts: 194
Joined: Mon Oct 24, 2016 10:55 pm
Location: Poland
Contact:

Re: How to use Trigger Callbacks

Postby PeterBibinin » Wed Sep 06, 2017 12:26 pm

Code: Select all

    void OnTriggerUsed(Player player)
    {
        DO THINGS
    }

    void OnTriggerUnUsed(Player player)
    {
        // The trigger has een unused
    }

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        throw new System.NotImplementedException();
    }

    bool ITriggerCallbacks.OnTriggerUnUsed(Player player)
    {
        throw new System.NotImplementedException();
    }
    }



Again OnTriggerUsed, OnTriggerUnUsed is a bool it's not a void.

Now I'm in job so I can't help you much but when I'm back I show you how this code should look.
Waiting for sunrise
-------------------------------------------
Try make world beter ;]

My Advanced Save System tutorial with screen capture like in The Forest !
Advanced Save System
-------------------------------------------
BAZINGA !

Adressa
Posts: 9
Joined: Wed Aug 30, 2017 6:55 pm

Re: How to use Trigger Callbacks

Postby Adressa » Wed Sep 06, 2017 6:54 pm

Oh damn I feel so stupid for not trying this, I think before it didn't work because I didn't change the "throw".

Code: Select all

    bool ITriggerCallbacks.OnTriggerUsed(Player player)
    {
        ES2.Save(lastWell, "LASTWELL.txt");
        Restore();
        GameManager.SaveGame();
        throw null;
    }

    bool ITriggerCallbacks.OnTriggerUnUsed(Player player)
    {
        throw null;
    }

So is this what I should be doing? The code works but it still throws the error for Used and UnUsed.
Also how would I make it work using only "Used", so next time I trigger it doesnt run "UnUsed", it does "Used" again?


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 0 guests