Page 1 of 2

Gif Player LuaScript Failure [Solved!]

Posted: Fri Oct 05, 2018 11:55 pm
by CodePrincess
Hello, everybody!

So I bought a gif player from OldMoat games and I wanted to be able to control which gifs play when from the comfort of my dialog editor. I wrote this script:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GifManager : MonoBehaviour {
    [SerializeField] public OldMoatGames.AnimatedGifPlayer[] Gif;

    public GifManager()
    { 

    }

    public void HideGif(double e)
    {
        Gif[(int)e].enabled = false;
    }

    public void ShowGif(double e)
    {
        Gif[(int)e].enabled = true;
    }

    private void OnEnable()
    {
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("HideGif", this, typeof(
            GifManager).GetMethod("GifManager"));
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("ShowGif", this, typeof(
           GifManager).GetMethod("GifManager"));
    }

    private void OnDisable()
    {
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("HideGif");
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("ShowGif");
    }
}
Plunked it in my Dialogue Manger, then used the functions in my editor, they looked like this:
GifFunctionCalls.png
GifFunctionCalls.png (32.42 KiB) Viewed 1624 times
When I ran the program, nothing happened.

Does anybody see a glaring error or two?

Thank you and take care!

Re: Gif Player LuaScript Failure

Posted: Sat Oct 06, 2018 8:45 am
by Tony Li
Hi,

Try this:

Code: Select all

ShowGif(Variable["Cheerful_Maya"])
HideGif(Variable["Cheerful_Maya_Talking"])
Lua variables match the names you've defined in your dialogue database except for certain special characters like spaces, as described in Important Note About Tables Indices. In Lua, characters such as spaces are replaced by underscores ( _ ).

Re: Gif Player LuaScript Failure

Posted: Sat Oct 06, 2018 12:10 pm
by CodePrincess
Try this:
CODE: SELECT ALL

ShowGif(Variable["Cheerful_Maya"])
HideGif(Variable["Cheerful_Maya_Talking"])
Okay, I did like you suggested and found a spelling error in my Variables list in the process (sweet!).
But after running the Lua functions again, even from the Dialog System Trigger that starts the conversation, the character still seems totally oblivious to the commands. :?

Is something overriding them?

I'm sorry for taking so much of your time, but thank you. I don't think I could figure this out on my own.

Re: Gif Player LuaScript Failure

Posted: Sat Oct 06, 2018 3:13 pm
by Tony Li
Hi,

Try the script below. I made two changes:

1. Got rid of the GifManager() constructor method. You don't need to define a constructor for MonoBehaviour classes.

2. More importantly, I changed GetMethod("GifManager") to GetMethod("ShowGif") and the same for HideGif. The original code was accidentally trying to get a method named GifManager() instead of ShowGif(). Sorry, I should've caught those before. I blame it on Saturday morning before coffee. ;-)

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GifManager : MonoBehaviour {
    [SerializeField] public OldMoatGames.AnimatedGifPlayer[] Gif;

    public void HideGif(double e)
    {
        Gif[(int)e].enabled = false;
    }

    public void ShowGif(double e)
    {
        Gif[(int)e].enabled = true;
    }

    private void OnEnable()
    {
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("HideGif", this, typeof(
            GifManager).GetMethod("HideGif"));
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("ShowGif", this, typeof(
           GifManager).GetMethod("ShowGif"));
    }

    private void OnDisable()
    {
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("HideGif");
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("ShowGif");
    }
}

Re: Gif Player LuaScript Failure

Posted: Sat Oct 06, 2018 5:46 pm
by CodePrincess
Alright! Now we're getting somewhere! :D
Okay, the starting animation stops running, no new gifs show up, but animation resumes after the conversation ends. I need to figure out how to render images visible/invisible now. enable alone won't do the trick. That sounds like a Unity job, so Google probably knows something...

Thank you again, and I'll update as soon as I figure this out!

Re: Gif Player LuaScript Failure

Posted: Sat Oct 06, 2018 6:01 pm
by Tony Li
If the "Cheerful Maya" AnimatedGifPlayer's GameObject is inactive, you may need to activate it:

Code: Select all

public void ShowGif(double e)
{
    Gif[(int)e].gameObject.SetActive(true);
    Gif[(int)e].enabled = true;
}

Re: Gif Player LuaScript Failure

Posted: Wed Oct 10, 2018 1:22 am
by CodePrincess
So the gifs are activating/deactivating when called, but only cheerful maya is ever drawn.
Do I really need to make every possible mistake before this project will let itself be done? :oops:

Here's my code:

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GifManager : MonoBehaviour {
    [SerializeField] public OldMoatGames.AnimatedGifPlayer[] Gif;
    [SerializeField] private bool[] doDraw;


    public void HideGif(double e)
    {
        Debug.Log("Hiding a gif: e = "+e);
        Gif[(int)e].gameObject.SetActive(false);
       // Gif[(int)e].enabled = false;
       // Gif[(int)e].Pause();
    }

    public void ShowGif(double e)
    {
        Debug.Log("Showing a Gif: e ="+e);
        Gif[(int)e].gameObject.SetActive(true);
      //  Gif[(int)e].enabled = true;
       //Gif[(int)e].Play();

    }
    

    private void OnEnable()
    {
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("HideGif", this, typeof(
            GifManager).GetMethod("HideGif"));
        PixelCrushers.DialogueSystem.Lua.RegisterFunction("ShowGif", this, typeof(
           GifManager).GetMethod("ShowGif"));
    }

    private void OnDisable()
    {
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("HideGif");
        PixelCrushers.DialogueSystem.Lua.UnregisterFunction("ShowGif");
    }
    void Start()
    {
        Debug.Log("GifManager.Start() was run.");

        for (int i = 0; i < Gif.Length; i++)
        {

             Gif[i].gameObject.SetActive(doDraw[i]);
            Gif[i].enabled = doDraw[i];

        }

    }
}
I understand if this is more work for you than could possibly be worth your trouble. But if not, thanks again.
:-)

Re: Gif Player LuaScript Failure

Posted: Wed Oct 10, 2018 8:20 am
by Tony Li
Hi,

I haven't used Animated GIF Player, and the documentation isn't online, so we may need to fumble a bit until we find the solution. :-)

What if you try uncommenting the lines that you commented out? Something like:

Code: Select all

public void HideGif(double e)
{
    Debug.Log("Hiding a gif: e = "+e);
    Gif[(int)e].gameObject.SetActive(false); // Once inactive, I think that's all you need to do here.
}

public void ShowGif(double e)
{
    Debug.Log("Showing a Gif: e ="+e);
    Gif[(int)e].gameObject.SetActive(true);
    Gif[(int)e].enabled = true;
    Gif[(int)e].Play(); // Assuming there's a Play() method.
}

Re: Gif Player LuaScript Failure

Posted: Thu Oct 11, 2018 2:08 pm
by CodePrincess
I think the problem is that using any gif player commands before all the gifs are loaded cause it to mess up. Yep, that's it! Now all I need to do is... the gif objects have just spontaneously deassigned their assets. I managed to reassign them, but now my trigger sprite looks like this:
thisisnew.png
thisisnew.png (201.02 KiB) Viewed 1598 times
And I can't trigger the conversation at all.

What would make the trigger act like that?

Re: Gif Player LuaScript Failure

Posted: Thu Oct 11, 2018 2:50 pm
by Tony Li
Hi,

Are you talking about the "Cheerful Maya - (spacebar to interact)" message?

Are there any errors in the Console window?