HELP! What could stop an allEntities search? diagnosing bug

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: HELP! What could stop an allEntities search? diagnosing

Post by petri »

Bug confirmed. It is caused by map markers - allEntities() has a bug which stops the iteration when it encounters a map marker. The One Room save game works if map markers are removed from the map by right-clicking on them.

Unfortunately we just released a patch today and building a new patch takes about 2 days (to build and test all the numerous SKUs we have is a lot of work) so we can't do another patch right now.
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: HELP! What could stop an allEntities search? diagnosing

Post by Xanathar »

Thanks petri! :)
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: HELP! What could stop an allEntities search? diagnosing

Post by petri »

Yeah, "thanks for writing rubbish code" :lol:
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: HELP! What could stop an allEntities search? diagnosing

Post by Komag »

Wow, I'm very happy to know the problem has been properly diagnosed!

So I suppose I'll have to use the 0,31 loops entitiesAt fix for now, and maybe in future months after a new Grimrock patch is released, and if I feel like it, I can revert back to allEntities for any updated versions of the project I release.

Thanks petri for getting to the bottom of this :)
Finished Dungeons - complete mods to play
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: HELP! What could stop an allEntities search? diagnosing

Post by Komag »

Here is my "solution":

- add a script entity to the dungeon and call it allEnt
- include this code in it:

Code: Select all

ties = function( level )

   local s = {}
   s["offset"] = 0
   local c = 0
   for i=0,31 do
      for j=0,31 do
         for k in entitiesAt(level,i,j) do
            c = c + 1
            s[c] = k
         end
      end
   end

   local f = function ( s , v )

      local offset = s["offset"] + 1
      s["offset"] = offset
      
      return s[offset]
   end

   return f , s , nil
end

-- this "function" is a replacement for allEntities due to
-- a bug discovered that if the player puts a map marker on
-- their automap during the game then allEntities won't
-- complete when it finds it, breaking scripts left and right!
-- This function substitutes 0,31 loops using entitiesAt which
-- doesn't exhibit the bug. petri says a future Grimrock patch
-- will fix the bug and allEntities will be back on the table
-- at that point.

-- function code by Marble Mouth, setup and notes by Komag
Save your dungeon, then close the editor (or don't, but be careful) and open your dungeon.lua file in notepad++ and do a search/replace

allEntities --> allEnt.ties

Save the file then close it and open the editor again (or if you left it open do "Reload Project" so you don't lose the changes)

Now all the allEntities will be allEnt.ties which uses the new function and they will all work and be reliable! :D

(I wonder how many problems players have had with various mods are due to this bug breaking scripts? :? )
Finished Dungeons - complete mods to play
Marble Mouth
Posts: 52
Joined: Sun Feb 10, 2013 12:46 am
Location: Dorchester, MA, USA

Re: HELP! What could stop an allEntities search? diagnosing

Post by Marble Mouth »

Hi again. I'm glad to see that the iterator I wrote was helpful. The way you've used it ( as a function named ties in a script entity named allEnt ) will definitely work. When I wrote it, I didn't take into account that this will only redefine allEntities within that script entity. If you've already gone ahead and done a search/replace then the following advice doesn't really apply. If you have a relatively small number of script entities that use allEntities, you can paste this at the top of each of them:

Code: Select all

allEntities = allEnt.ties
Then you can just comment out that line if you wanted to go back to using the standard definition of allEntities in that script entity after it gets patched. I would recommend going back to the standard at that point.

Petri and all the devs, my sincere thanks to all of you for Grimrock. Not every studio takes ownership of their bugs, but every developer has them. This is the fastest that I've ever seen a developer respond to a possible bug report without definite steps to reproduce the problem.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: HELP! What could stop an allEntities search? diagnosing

Post by Grimfan »

hi, I've run into a little problem involving Komag's modified version of the iterator.

The iterator does not come up with an error for the rest of my scripts, but when I use it in Xanathar's chestmanager script I get the following:

Code: Select all

 function activateAll()
	local MAXLEVEL = getMaxLevels()
	for l = 1, MAXLEVEL do
		trace("checking level ".. l .. " for chests")
		for itm in allEnt.ties(l) do --- (attempt to call field 'ties', a nil value)
			if (CHESTMODELS[itm.name] ~= nil) then
				trace("creating chest " .. itm.id)
				addchest(itm)
			end
		end
	end
end
Pity I can't change the font color for a code. :|

Anyone know what's going on?
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: HELP! What could stop an allEntities search? diagnosing

Post by Xanathar »

hi :)

First of all the main thing: 99.999% you don't need to do that change. In fact that function runs once and only once at the first time you create a new game, so the player had no chance to create any map marker yet! You only need it if you are going to put map markers directly in the editor, which isn't likely to happen, imho.

Anyway, if you really want to change it anyway, you have to copy that function into the chestmanager scripting entity itself. The reason it's failing is that when the chestmanager runs the other scripting entities might not be initialized yet.
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
Marble Mouth
Posts: 52
Joined: Sun Feb 10, 2013 12:46 am
Location: Dorchester, MA, USA

Re: HELP! What could stop an allEntities search? diagnosing

Post by Marble Mouth »

Excellent points, Xanathar. For anyone using allEntities in a startup script, there are no player placed map markers to worry about. For one reason or another, a lot of scripts use allEntities in places where findEntity would also work ( and probably would work better. ) I'm very guilty of this.

Script entities seem to initialize in the same order that they were added to the editor, but I haven't confirmed this. Examining dungeon.lua suggests that the order could be: every script_entity in level 1, in the order that they were created, then every script_entity in level 2, in the order that they were created, and so on. In the past, I've had to cut/paste an entire script_entity into a new script_entity just to force it to initialize after some other script ( not necessarily allEnt ) that it's trying to use on startup. I've been trying to figure out a scheme that will yield the benefits of initialize-on-first-use, but no luck yet. Meanwhile, I have confirmed that it's possible to rearrange the spawn commands in dungeon.lua ( with any text/code editor ) to change the initialization order, but be very careful if you're going to make changes directly in dungeon.lua . Make backups first.

Or you could paste the whole allEntities redefinition at the top of any script_entity that you like. Then, for the rest of that specific script_entity ( unless you redefine allEntities again ) everywhere that the code says "allEntities" will use the redefined function, not the standard. This is not the preferred method: Suppose someone finds a bug in my code and posts a bug fix. Then you'll find that you have some number of script_entity s, each of which has to be updated individually. This is more work, and more room for human error. If you had only pasted the redefinition in one place and then referenced it from everywhere else, you would only have one script to update with the bug fix. Less work, less room for error.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: HELP! What could stop an allEntities search? diagnosing

Post by Komag »

I have quite a few scripts in my dungeon only start after a 0.05s timer triggers them all, so everything else can initialize first :)
Finished Dungeons - complete mods to play
Post Reply