[Solved] If statemens on Dialogue Entries

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jordyadan
Posts: 2
Joined: Fri Jul 13, 2018 1:11 pm

[Solved] If statemens on Dialogue Entries

Post by jordyadan »

Hello,

I've been trying to use if statements in the Dialogue Entry's Text and Script sections with no success. What I'm trying to do is access a boolean variable called "Test" and choose an outcome based on wether it is true or false.

Here's my Dialogue Text:

Code: Select all

Test is true: [lua( if (Variable["Test"]==true) then "Yes" else "Nope" end )]
I've also tried putting it on the Script's box, using the result to set a text variable, also with no success.

Is my lua syntax wrong?
Last edited by jordyadan on Mon Jul 16, 2018 12:04 pm, edited 1 time in total.
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: If statemens on Dialogue Entries

Post by Tony Li »

Hi,

Internally, the [lua] tag puts the "return" keyword in front of your expression. The result is that this doesn't make sense to it:

Code: Select all

return if (Variable["Test"]==true) then "Yes" else "Nope" end
The solution is to use this syntax instead:

(condition) and (true-value) or (false-value)

Like this:

Code: Select all

Test is true: [lua( (Variable["Test"]==true) and "Yes" or "Nope" )]
jordyadan
Posts: 2
Joined: Fri Jul 13, 2018 1:11 pm

Re: If statemens on Dialogue Entries

Post by jordyadan »

Got it to work, Tony Li, thank you!
User avatar
Tony Li
Posts: 22058
Joined: Thu Jul 18, 2013 1:27 pm

Re: [Solved] If statemens on Dialogue Entries

Post by Tony Li »

Happy to help!
Post Reply