Ankoku / df-webfort

Web Fortress
ISC License
35 stars 10 forks source link

Plugin Errors On Player Switch - 40.16 test release 2 #41

Closed Dragoon209 closed 9 years ago

Dragoon209 commented 9 years ago

Whenever a player connects and starts playing, or control reverts back to nobody, I get the following error in the DF Hack Console:

[2014-12-02 18:31:46] [connect] WebSocket Connection [::ffff:xx.x.xxx.xx]:56506 v13 "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/39.0.2171.71 Safari/537.36" /totally 101
C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:63: bad argument #1 to 'random' (interval is empty)
stack traceback:
        [C]: in function 'random'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:63: in function 'choice'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:119: in function 'main'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:126: in main chunk
        (...tail calls...)
[2014-12-02 18:32:10] [WEBFORT] totally is now active.
The game should save the state now.
[2014-12-02 18:32:12] [WEBFORT] __NOBODY is now active.
C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:63: bad argument #1 to 'random' (interval is empty)
stack traceback:
        [C]: in function 'random'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:63: in function 'choice'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:119: in function 'main'
        C:\Users\DF\Desktop\df_40_16\hack\scripts/deify.lua:126: in main chunk
        (...tail calls...)
[2014-12-02 18:32:14] [WEBFORT] totally is now active.

The slashes seem to be in the wrong direction after the 'scripts' folder, but since it still ran the script, I'm not sure that is the problem.

Alloyed commented 9 years ago

that should be harmless, but at the same time the error ruins a bit of the mystique. a quick patch, should be included next build:

diff --git a/dist/shared/hack/scripts/deify.lua b/dist/shared/hack/scripts/deify.lua
index 7ade81f..ccf8c70 100644
--- a/dist/shared/hack/scripts/deify.lua
+++ b/dist/shared/hack/scripts/deify.lua
@@ -60,6 +60,7 @@ function make_set(list)
 end

 function choice(list)
+       if #list < 1 then return nil end
        return list[math.random(#list)]
 end