Gif Player LuaScript Failure [Solved!]

Announcements, support questions, and discussion for the Dialogue System.
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Gif Player LuaScript Failure [Solved!]

Post 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 1622 times
When I ran the program, nothing happened.

Does anybody see a glaring error or two?

Thank you and take care!
Last edited by CodePrincess on Wed Oct 24, 2018 6:51 pm, edited 1 time in total.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Gif Player LuaScript Failure

Post 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 ( _ ).
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Gif Player LuaScript Failure

Post 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.
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Gif Player LuaScript Failure

Post 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");
    }
}
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Gif Player LuaScript Failure

Post 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!
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Gif Player LuaScript Failure

Post 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;
}
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Gif Player LuaScript Failure

Post 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.
:-)
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Gif Player LuaScript Failure

Post 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.
}
CodePrincess
Posts: 111
Joined: Thu Sep 27, 2018 11:06 pm

Re: Gif Player LuaScript Failure

Post 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 1596 times
And I can't trigger the conversation at all.

What would make the trigger act like that?
Thank you so much for your help.

Oh! My stats!
Unity 2020.1.10f1
Adventure Creator 1.72.2
Dialogue System for Unity 2.2.12
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Gif Player LuaScript Failure

Post by Tony Li »

Hi,

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

Are there any errors in the Console window?
Post Reply