Question about GetParameter.

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mac
Posts: 81
Joined: Sat Aug 22, 2020 7:54 pm

Question about GetParameter.

Post 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.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Question about GetParameter.

Post by Tony Li »

Hi,

GetParameter() returns a string.

To get an int, use GetParameterAsInt():

Code: Select all

int index = GetParameterAsInt(0);
mac
Posts: 81
Joined: Sat Aug 22, 2020 7:54 pm

Re: Question about GetParameter.

Post by mac »

Holy I feel so dumb now, it was that easy, sorry for such a dumb question and thanks once again Tony.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Question about GetParameter.

Post by Tony Li »

There are no dumb questions. Glad to help!
Post Reply