Page 1 of 1

If Then Variable in Node Script

Posted: Wed Oct 19, 2022 4:02 pm
by BWLGeorge
Howdy!

I'm trying to do some Icarian complicated branching dialogue stuff, and I'm just trying to make sure I understand the Conditional command or not.

Basically the idea is that the dialogue changes based on the order in which the player learned information, and I'm trying to use a number variable that will change based on that.

In my example code here, 0 means the player hasn't talked to either A or B. Talking to character A sets it to 1, talking to character B sets it to 2. But I want to make it so that if you have talked to character B before talking to character A, it will be set to 3 (and subsequently if you talked to A before talking to B, it will be set to 4.) Does this code look like it should do the job?

Character A conversation node:
Conditional("Variable['Sanctuarywasfoulplay'] == 0",
Variable["Sanctuarywasfoulplay"] = 1;
Conditional("Variable['Sanctuarywasfoulplay'] == 2",
Variable["Sanctuarywasfoulplay"] = 3;

And then the inverse for Character B:
Conditional("Variable['Sanctuarywasfoulplay'] == 0",
Variable["Sanctuarywasfoulplay"] = 2;
Conditional("Variable['Sanctuarywasfoulplay'] == 1",
Variable["Sanctuarywasfoulplay"] = 4;

Re: If Then Variable in Node Script

Posted: Wed Oct 19, 2022 5:21 pm
by Tony Li
Hi,

The Conditional() Lua function is usually used inside a [lua(code)] markup tag in Dialogue Text, although you can use it anywhere Lua is accepted, such as Conditions and Script fields.

However, Conditional() might not be what you want. Conditional(a, "b") evaluates a. If it's true, it returns b. Otherwise it returns a blank string. It doesn't set any values.

Instead, you can use one or both of these approaches:

1. In the dialogue entry's Script field, write an if-elseif-else expression like:

Code: Select all

if (Variable['Sanctuarywasfoulplay'] == 0) then
     Variable["Sanctuarywasfoulplay"] = 1;
elseif ("Variable['Sanctuarywasfoulplay'] == 2) then
    Variable["Sanctuarywasfoulplay"] = 3;
end

2. And/or use two separate dialogue entry nodes, linked from the same originating node:

Node 1:
  • Conditions: Variable['Sanctuarywasfoulplay'] == 0
  • Script: Variable['Sanctuarywasfoulplay'] = 1
Node 2:
  • Conditions: Variable['Sanctuarywasfoulplay'] == 2
  • Script: Variable['Sanctuarywasfoulplay'] = 3
You'll probably want a third node in case Variable['Sanctuarywasfoulplay'] is neither 0 nor 2. If you make this the third node in the originating node's Links To: list, it will only be used if the other nodes' Conditions are false.

Re: If Then Variable in Node Script

Posted: Wed Oct 19, 2022 8:29 pm
by BWLGeorge
Ahhh, that makes a lot of sense. That first method was what I was putting together originally until I stumbled on the Conditional function.

Thanks for the tips!

Re: If Then Variable in Node Script

Posted: Wed Oct 19, 2022 10:23 pm
by Tony Li
Happy to help!