We tried to make script in dialogue a bit more complex (and we don't have any lua experience) and got this error:
Dialogue System: Lua code 'if Variable["TrainStartSequence"] == 0 then Variable["TrainStartSequence"] = 1' threw exception 'Code has syntax errors:
Line 2, Col 1 : Failed to parse Letter of Name.
Line 2, Col 1 : Failed to parse Name of VarName.
Is it possible to use if/then statement in script field? And if it is possible, how to do it properly?
Script with if/then exception
Re: Script with if/then exception
Hi,
Lua is mostly like C#, but 'if' statements are a little different because that have to end with the 'end' keyword. Try this:
Or, for better readability:
Alternatively, you could use math.max() to guarantee that the variable is at least 1:
Lua is mostly like C#, but 'if' statements are a little different because that have to end with the 'end' keyword. Try this:
Code: Select all
if Variable["TrainStartSequence"] == 0 then Variable["TrainStartSequence"] = 1 end
Code: Select all
if (Variable["TrainStartSequence"] == 0) then
Variable["TrainStartSequence"] = 1
end
Code: Select all
Variable["TrainStartSequence"] = math.max(1, Variable["TrainStartSequence"])
Re: Script with if/then exception
Thanks for the quick response!
Re: Script with if/then exception
Glad to help!