OnlineCop / kq-fork

Fork of KQ r910. Just for fun.
GNU General Public License v2.0
15 stars 9 forks source link

The party[] array in Lua scripts is nil #159

Open OnlineCop opened 1 year ago

OnlineCop commented 1 year ago

While troubleshooting the coliseum crash when entering Rufus' cabin, I noticed that interacting with the fire calls touch_fire(party[0]), but the party[] array appears to be nil.

It appears to also be nil in the other scrips where party[#] is used, such as book_talk(party[0]).

Do we have any idea where party gets initialized and/or updated? Is it within the Lua scripts, or back in the C++ code like in intrface.cpp somewhere?

z9484 commented 1 year ago

Ugh I finally found it https://github.com/OnlineCop/kq-fork/blob/road_to_1.0/src/intrface.cpp#L923 Works on my machine(on pass.tmx). I have got that nil error before though. I think it might have been when the lua interpreter crashed for a map, so it was in a weird state.

OnlineCop commented 1 year ago

I'm not sure; I started a new game and started to read bookshelves and fires where touch_fire() or book_talk() were used with party[...] and am seeing those errors (not just in the pass where the parallax may be causing some kind of error).

When the interpreter crashes, doesn't it usually dump an error to screen (still recoverable, and player can keep going)?

z9484 commented 1 year ago

Yes it should print an error to the console and then keep going. I started a new game and book_talk worked. Are using mac or linux?

OnlineCop commented 1 year ago

Actually, Win10. I wonder if Lua broke silently and I just don't see any error messages about it?

Watching a tutorial now (Lua C API tutorial) to see whether it was something with my Lua stack that I implemented wrong.

I've got an uneasy feeling that it has something to do with the fact that KPlayer is a C++ class (with std::string types) and KQEntity is a C-style POD (with plain length-known-at-compile-time char[] arrays)... I might need to make a KQPlayer POD (plain-old-data) struct to use instead.