Variable Reading as 'nil'

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
AlexNerd
Posts: 39
Joined: Sat Jun 29, 2019 11:46 am

Variable Reading as 'nil'

Post by AlexNerd »

I'm trying to have a variable that decrements by one when a player clicks on certain objects. However, the triggers weren't working so I put a print statement in the Lua code, and apparently it's being read as 'nil' even though I put an initial value in the Dialogue System. Any help would be appreciated!
Capture.JPG
Capture.JPG (33.14 KiB) Viewed 433 times
Capture.JPG
Capture.JPG (120.74 KiB) Viewed 433 times
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable Reading as 'nil'

Post by Tony Li »

Hi Alex,

Use:

Code: Select all

print(Variable["Valves_Turned"])
AlexNerd
Posts: 39
Joined: Sat Jun 29, 2019 11:46 am

Re: Variable Reading as 'nil'

Post by AlexNerd »

Thank you! I'm still new to Lua, sorry.
User avatar
Tony Li
Posts: 21981
Joined: Thu Jul 18, 2013 1:27 pm

Re: Variable Reading as 'nil'

Post by Tony Li »

No problem! Your original code was perfectly valid Lua. It's just that the Dialogue System stores all of its dialogue database variables in a Lua array named Variable[]. So to access a dialogue database variable, you need to specify the Variable[] array.
AlexNerd
Posts: 39
Joined: Sat Jun 29, 2019 11:46 am

Re: Variable Reading as 'nil'

Post by AlexNerd »

That makes sense. I'll have to remember that for the future.
Post Reply