이번 시간에는 배열을 사용하는 방법에 대해서 배워보겠습니다. 아래의 예제를 살펴보면, "what color is my blue shirt?"라고 물어보는 질문에 color와 와일드 카드를 통해서 bot은 응답하도록 되어있습니다.
+ what color is my (red|blue|green|yellow) * - Your <star2> is <star1>, silly!
()안에 몇가지 color들이 정의된 것을 볼 수 있습니다. 이렇게 사용해도 되지만 color가 필요한 트리거가 몇가지 더 생길 수가 있습니다. 그럼 그때마다 (red|blue|green|yellow)이 내용을 복사해서 붙여넣기 해야되고 그렇게 한다고 하더라도 나중에 black, white등의 color가 새로 추가 될때에는 기존의 스크립트를 다 찾아서 수정하기에는 어려움이 있습니다. 그래서 RiveScript에서는 배열(Arrays)을 통해서 이러한 문제점을 해결 할 수 있습니다.
배열은 ! array 커멘드를 통해서 정의가 됩니다. 이전 시간에 정의하는 모든 커멘드는 begin.rive에 작성되어야 된다고 설명드렸습니다. 그렇게 때문에 배열 또한 begin.rive에 작성되어야 합니다.
! array colors = red blue green yellow
이제 우리는 배열을 정의할 수 있습니다. 다음 예제를 통해서 배열을 어떻게 활용하는지 알아보겠습니다.
+ what color is my (@colors) * - Your <star2> is <star1>, silly! - Do I look dumb to you? It's <star1>! + i am wearing a (@colors) shirt - Do you really like <star>?
예제에서 보시는거와 같이 <star>태그를 사용할 수 있으며 사용하지 않는 경우에는 ()를 제거해주면 됩니다.
// Without parenthesis, the array doesn't go into a <star> tag. + what color is my @colors * - I don't know what color your <star> is.
배열은 optionals에서도 적용할 수 있지만 <star>태그를 안에 사용할 수 는 없습니다.
왜냐하면 옵션은 생략 가능 하기 때문입니다.
// Arrays in an optional + i am wearing a [@colors] * - Do you really like <star>?
배열을 정의할때 배열 항목을 공백 (단일 단어에 유용함) 또는 파이프 기호 (|)로 구분할 수 있습니다.
// Single word array items ! array colors = red blue green yellow // Multiple word items ! array blues = light blue|dark blue|medium blue
배열을 정의 할 때 Continuations를 사용하면 각 행의 항목을 공백으로 또는 파이프로 나뉠 수 있습니다.
// A lot of colors! ! array colors = red blue green yellow orange cyan fuchsia magenta ^ light red|dark red|light blue|dark blue|light yellow|dark yellow ^ light orange|dark orange|light cyan|dark cyan|light fuchsia ^ dark fuchsia|light magenta|dark magenta ^ black gray white silver ^ light gray|dark gray
'프로그래밍 > RiveScript' 카테고리의 다른 글
[Tutorial] Redirections (0) | 2017.03.09 |
---|---|
[Tutorial] Priority Triggers (0) | 2017.03.08 |
[Tutorial] Alternatives and Optionals (0) | 2017.03.07 |
[Tutorial] TRIGGERS (0) | 2017.03.07 |
[Tutorial] The Begin File (0) | 2017.03.07 |