• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua tfs 1.2 odd bug

Zombiegod

Member
Joined
Oct 22, 2009
Messages
198
Solutions
1
Reaction score
24
so i am using this script Action - [TFS 1.1] Fishing monsters (https://otland.net/threads/tfs-1-1-fishing-monsters.229702/)

and whenever i first load the server it complains about this
Code:
Monster fishing::Warning - Invalid monster name:        Sea Serpent
Monster fishing::Warning - Invalid monster name:        Rotworm
Monster fishing::Warning - Invalid monster name:        Dragon
Monster fishing::Warning - Invalid monster name:        Rat
Monster fishing::Warning - Invalid monster name:        storage
Monster fishing::Warning - Invalid monster name:        EXP
Monster fishing::Warning - Invalid monster name:        Serpent Spawn
Monster fishing::Warning - Invalid monster name:        Wyrm
Monster fishing::Warning - Invalid monster name:        Sea Serpent
Monster fishing::Warning - Invalid monster name:        Rotworm
Monster fishing::Warning - Invalid monster name:        Dragon
Monster fishing::Warning - Invalid monster name:        Rat
Monster fishing::Warning - Invalid monster name:        storage
Monster fishing::Warning - Invalid monster name:        EXP
Monster fishing::Warning - Invalid monster name:        Serpent Spawn
Monster fishing::Warning - Invalid monster name:        Wyrm

and wont let me fish, (they are all valid monsters) however if i /reload actions, it fixes and i can fish monsters like normal.

My guess it it has to do with the code being loaded before monsters get loaded, and that when i reload it registers the now loaded monsters.

The part of the code that spits out the error is this.
Lua:
if config.verifyMonsters then
    local m = {}
    for minLevel, monsters in pairs(config.monsters) do
        m[minLevel] = {}
        if config.debug then print("#monsters", #monsters) end
        for i = 1, #monsters do
            if MonsterType(monsters[i]) then
                table.insert(m[minLevel], monsters[i])
            else
                print("Monster fishing::Warning - Invalid monster name:", monsters[i])
            end
        end
        if config.debug then print("Monster fishing::Debug - #monsters added", #m[minLevel]) end
    end
    config.monsters = m
end
 
Solution
I just put the script in data/actions and changed the script for fishing rod (id 2580) in actions.xml.

Did you try the script exactly as is, without changing anything? You should get a single warning:
Monster fishing::Warning - Invalid monster name: Idontexist
Actually looks like this issue was just touched upon by a recent commit. And that new default behavior the original script should work as-is.
Good find. I pulled and built latest source yesterday just to be sure but I didn't think to replace config.lua so I didn't have the new variable. I haven't looked closely enough to tell whether that would load monster(type)s earlier, or just additionally load ones that are not spawned immediately though.
Just to clear up for future reference.
Monsters are loaded after the Scripting Interface (classic or revscriptsys doesn't matter)
The problem in this case was a flaw of design in the script itself, which @forgee pointed out pretty well just now.
There is a huge difference between those 3 pieces (just example codes)
Very well explained. đź‘Ť When I wrote the script originally, I simply didn't realize that the script system was loaded before monsters, so that's on me.
 
Just to clear up for future reference.
Monsters are loaded after the Scripting Interface (classic or revscriptsys doesn't matter)
~~
It's all just a matter of order and execution, this is a heavy topic and I just gave a shallow explanation of it, this can go even beyond all of this but it should give a slight idea of why this is not working.

Seems like the initial decision for it was probably simple enough. Monsters may depend on scripts, so scripts get loaded first.


I haven't looked closely enough to tell whether that would load monster(type)s earlier, or just additionally load ones that are not spawned immediately though.

Examining the code, it seems globalStorageTable is not saved, it is ephemeral and it's state is completely a matter of the current execution context.

So an alternative solution would be to run the verifyMonsters check on the first usage of the fishing pole, state tracked in a globalStorage.
 
That is presuming of course, the order in which the Lua environment is constructed? Given the possibility of revscriptsys monsters?
 
The order doesn't really matter in this case, the chunk is loaded once the scripting system gets initialized but the execution which is important is once the interface is called.
That brings me back to the example I've just posted, if the function is called inside the interface (or an underlying function declared outside the interface) then it's safe to go.
 
Thanks everyone! i made the adjustments and turned it into a local function, at least for now. It is current;y working flawlessly (to the best of my knowledge.).
 
Back
Top