Page 1 of 1

Question about GetParameter.

Posted: Fri Apr 22, 2022 2:09 am
by mac
Hello Tony, so I'm trying to make a custom sequencer command to change my dialogue background Image, thats the script:

Code: Select all

using UnityEngine;
using System.Collections;
using PixelCrushers.DialogueSystem;
using UnityEngine.UI;

namespace PixelCrushers.DialogueSystem.SequencerCommands
{

    public class SequencerCommandChangeBackground : SequencerCommand
    { // Rename to SequencerCommand<YourCommand>

        public void Awake()
        {
            int index = GetParameter(0); // error CS0029: Cannot implicitly convert type 'string' to 'int'

            Image background = GameObject.Find("Dialogue Background").GetComponent<Image>();

            background.sprite = Resources.Load<Sprite>("Backgrounds/" + index.ToString());

            Stop();
 
        }

    }

}
But it seems I'm using GetParameter() wrongly, what I thought is that I would use ChangeBackground(3) in the sequence space in my dialogue entry, so my index would be 3, but GetParameter can only take strings? How can I make it take ints so I can achieve my goal with this Custom Sequencer Command?
Thanks in advance, have a nice weekend Tony.

Re: Question about GetParameter.

Posted: Fri Apr 22, 2022 7:07 am
by Tony Li
Hi,

GetParameter() returns a string.

To get an int, use GetParameterAsInt():

Code: Select all

int index = GetParameterAsInt(0);

Re: Question about GetParameter.

Posted: Fri Apr 22, 2022 9:57 pm
by mac
Holy I feel so dumb now, it was that easy, sorry for such a dumb question and thanks once again Tony.

Re: Question about GetParameter.

Posted: Fri Apr 22, 2022 10:17 pm
by Tony Li
There are no dumb questions. Glad to help!