Page 1 of 1

A couple of Lua bugs and a suggestion

Posted: Wed Feb 15, 2017 3:43 am
by GroundCombo
I bumped into some oddities while hooking up some game features into the built-in Lua interpreter:

Code: Select all

local foo = 4
for i = foo, 1, -1 do ... end
print(foo)
...prints 0. If you assign foo to some other variable before the loop, that variable gets modified too. You can work around this by forcing the interpreter to evaluate an expression instead of an assignment, like this:

Code: Select all

for i = foo+1-1, 1, -1
Another bug is that table.getn() throws an exception for a 'new LuaTable()' that hasn't been used. It doesn't seem to properly check for null list/dict values.

These aren't big problems and they can be worked around, but I thought I'd mention them anyway.

Also, it would be nice to have a QuestEntryStateChanged event, with the quest and entry number; this might be a bit tricky with how BroadcastMessage() is currently used for sending dialogue events, but it would make detailed quest tracking easier. I've solved it for now by overriding the default SetQuestEntryState Lua function.

Thanks for an excellent asset.

Re: A couple of Lua bugs and a suggestion

Posted: Wed Feb 15, 2017 8:37 am
by Tony Li
Hi,

Thank for reporting those Lua bugs! I'll try to get them fixed for the next release.

When you overrode SetQuestEntryState(), what did you end up passing? Did you still use BroadcastMessage(), Unity's event message system, something else? For better consistency with the existing messages, I'm thinking of adding an option to send a struct with the quest title and entry number, rather than switching to a new paradigm like Unity's event message system.

Re: A couple of Lua bugs and a suggestion

Posted: Wed Feb 15, 2017 10:36 am
by GroundCombo
Basically I added a new UnityEvent<string, int> to DialogueSystemEvents, unregistered the existing SetQuestEntryState() and registered a replacement that takes the appropriate arguments and invokes the event.

Passing a struct would also be completely fine.

Re: A couple of Lua bugs and a suggestion

Posted: Wed Feb 15, 2017 10:52 am
by Tony Li
Thanks! I'll probably do both of those things.