crash

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

crash

Post by bongobeat »

good evening,

someone can help about a crash please?
I got this crash when I throw some items on an altar.

when the correct items are put, it check for a script, destroy the altar and the items, spawn a new altar with another item.

if the items are placed "normally", I mean if you don't throw them, there is no problem.

here is the log:
SpoilerShow
[string "SoundSystem.lua"]:0: attempt to index a nil value
stack traceback:
[string "SoundSystem.lua"]: in function 'playSound3D'
[string "Item.lua"]: in function 'onProjectileHit'
[string "Projectile.lua"]: in function 'update'
[string "Item.lua"]: in function 'update'
[string "Map.lua"]: in function 'updateEntities'
[string "Dungeon.lua"]: in function 'updateLevels'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk

OS Version 6.1

OEM ID: 0
Number of processors: 4
Page size: 4096
Processor type: 586

Total memory: 3560 MB
Free memory: 1086 MB

Display device 0:
Device name: \\.\DISPLAY1
Device string: NVIDIA GeForce GTX 660
State flags: 00000005

Display device 1:
Device name: \\.\DISPLAY2
Device string: NVIDIA GeForce GTX 660
State flags: 00000000

Display device 2:
Device name: \\.\DISPLAY3
Device string: NVIDIA GeForce GTX 660
State flags: 00000000

Display device 3:
Device name: \\.\DISPLAY4
Device string: NVIDIA GeForce GTX 660
State flags: 00000000

Display device 4:
Device name: \\.\DISPLAYV1
Device string: RDPDD Chained DD
State flags: 00200008

Display device 5:
Device name: \\.\DISPLAYV2
Device string: RDP Encoder Mirror Driver
State flags: 00200008

Display device 6:
Device name: \\.\DISPLAYV3
Device string: RDP Reflector Display Driver
State flags: 00200008
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: crash

Post by Isaac »

Most likely it is that you are calling a sound effect in the code that is not in the correct format. Sounds that are placed in the 3d world cannot be stereo, they have to be mono, and should be 16-bit/44.1kHz .
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: crash

Post by minmay »

This happens because you're destroying the item as soon as the altar is triggered. When a thrown item lands, it plays its impact sound, but when it lands on an altar, it will trigger that altar's connectors first. So if you destroy the item inside a script triggered by an altar, the game will look for the item's impact sound after your script executes - and as the item no longer exists, it will just attempt to index a nil value instead.

You can work around this by destroying the item after a very short delay instead (e.g. with a 1 millisecond timer).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: crash

Post by Isaac »

As minmay has suggested. This is better. 8-)
(I was too quick with assumptions; usually when I get a sound system error, it's my mistake with the format.)
_______________________

You can spawn a timer to delete the items and then remove itself.

This is an example that would have to be adapted, but shows one method for it.

(To test it, just add the script to a map and connect a button; press the button as fast as you like, it spawns a timer that then calls the "remove_alcoveItems" code, and it will not generate duplicate IDs.)

Code: Select all

function remove_alcoveItems(caller)

	print("run alcove clean up code", caller.id) --Replace this line with your destroy Item code.
	
	caller:destroy()
	
end

function alcoveHelper()

	local alcove_clean_up = "alcove_"..getStatistic("play_time")
	spawn("timer", party.level, 1,1,1, alcove_clean_up )
		:setTimerInterval(0.01)
		:addConnector("activate", "alcove_script_1" , "remove_alcoveItems" )  
		:activate()

end
User avatar
msyblade
Posts: 792
Joined: Fri Oct 12, 2012 4:40 am
Location: New Mexico, USA
Contact:

Re: crash

Post by msyblade »

Absolutely the answer. 0.1 delay between scripts should be fine
Last edited by msyblade on Fri Jul 04, 2014 8:11 pm, edited 1 time in total.
Currently conspiring with many modders on the "Legends of the Northern Realms"project.

"You have been captured by a psychopathic diety who needs a new plaything to torture."
Hotel Hades
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: crash

Post by bongobeat »

thanks for your answers.

Yes I see now. I will try some, thanks :)
Isaac wrote:As minmay has suggested. This is better. 8-)
(I was too quick with assumptions; usually when I get a sound system error, it's my mistake with the format.)
_______________________

You can spawn a timer to delete the items and then remove itself.

This is an example that would have to be adapted, but shows one method for it.

(To test it, just add the script to a map and connect a button; press the button as fast as you like, it spawns a timer that then calls the "remove_alcoveItems" code, and it will not generate duplicate IDs.)

Code: Select all

function remove_alcoveItems(caller)

	print("run alcove clean up code", caller.id) --Replace this line with your destroy Item code.
	
	caller:destroy()
	
end

function alcoveHelper()

	local alcove_clean_up = "alcove_"..getStatistic("play_time")
	spawn("timer", party.level, 1,1,1, alcove_clean_up )
		:setTimerInterval(0.01)
		:addConnector("activate", "alcove_script_1" , "remove_alcoveItems" )  
		:activate()

end
thank you for this example :)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: crash

Post by bongobeat »

Ok I have modify the script with yours:
there is no problem with throwing items anymore but another one comes while testing, I have never noticed this one before (on the ancient script I mean, but the issue was already here) :shock: :

the destroy/spawn start even if not the correct number of items are put:

eg:

here is the script:
SpoilerShow

Code: Select all

    function remove_alcoveItems(caller)

   local valid = {"old_primal_ore", "old_primal_ore", "old_primal_ore", "old_primal_ore", "crafting_hammer"}
	local counter = 0   

   for i in afor12:containedItems() do
      local ok = false
      for j = 1,#valid do
         if i.name == valid[j] then
            counter = counter + 1
            ok = true
            break
         end
      end
      if not ok then
         counter = -1
         break
      end
   end
   
  -- print(counter)
   
   if counter == 5 then
if findEntity("afor12") ~= nil then
for i in afor12:containedItems() do
i:destroy()
end
afor12:destroy()
spawn("deep_temple_altar", 20, 19, 30, 3, "afor12")
playSound("Volcano")
spawn("fireburst", 20, 19, 30, 3)
spawn("shockburst", 20, 19, 30, 3)
spawn("fireburst", 20, 19, 30, 3)
spawn("fireburst", 20, 19, 30, 3)
afor12:addItem(spawn("primal_boots"))
playSound("discover_spell")
hudPrint("You have forged an item, but the forge seems to be damaged now!")
   end
end
       
       caller:destroy()
       
    end

    function alcoveHelper()

       local alcove_clean_up = "alcove_"..getStatistic("play_time")
       spawn("timer", party.level, 1,1,1, alcove_clean_up )
          :setTimerInterval(0.01)
          :addConnector("activate", "alcove_script_5" , "remove_alcoveItems" ) 
          :activate()

    end
it is named "alcove_script_5" and linked to an altar, with activate always enabled.
here you need to place 4 "primal_ore" and 1 "crafting_hammer" but the script will work and spawn a new item even if you put 5 "primal_ore" or 5 "crafting_hammer"

seems that the script lony take the number of items as reference, counts 5 items, one of the 2 required and that's all.
I expected that it take the id and the number as reference.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: crash

Post by Isaac »

I haven't looked closely at it yet... but I can guess that it might have something to do with the "Always Activate" ~~This is a hunch.

I will look at it closer and post back.
User avatar
Allanius2
Posts: 124
Joined: Mon Apr 14, 2014 10:12 pm

Re: crash

Post by Allanius2 »

Of course the problem is there. Each item on the altar only has to match one of the items in the valid list. I would try something like this:

Code: Select all

function remove_alcoveItems(caller)

   local counter_1 = 0   
   local counter_2 = 0

   for i in afor12:containedItems() do
      if i.name == "old_primal_ore" then
            counter_1 = counter_1 + 1 -- this counts the ores
      elseif i.name == "crafting_hammer" then
           counter_2 = counter_2 + 1 -- this counts the hammers
      else
           -- invalid object found
      end
   end

   if counter_1 == 4 and counter_2 = 1 then
       -- trigger the destroy and and alter code here
   end
end
Try this and see if it works. Good luck.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: crash

Post by bongobeat »

ho many thanks!

this works fine! :)
(you guys are realy incredible!)

here is the final script if someone want's it:
SpoilerShow

Code: Select all

function remove_alcoveItems(caller)

   local counter_1 = 0   
   local counter_2 = 0

   for i in afor12:containedItems() do
      if i.name == "old_primal_ore" then
            counter_1 = counter_1 + 1 -- this counts the ores
      elseif i.name == "crafting_hammer" then
           counter_2 = counter_2 + 1 -- this counts the hammers
      else
           -- invalid object found
      end
   end

   if counter_1 == 4 and counter_2 == 1 then
      if findEntity("afor12") ~= nil then
for i in afor12:containedItems() do
i:destroy()
end
afor12:destroy()
spawn("deep_temple_altar", 20, 19, 30, 1, "afor12")
playSound("Volcano")
spawn("fireburst", 20, 19, 30, 1)
spawn("shockburst", 20, 19, 30, 1)
spawn("fireburst", 20, 19, 30, 1)
spawn("fireburst", 20, 19, 30, 1)
afor12:addItem(spawn("primal_boots"))
playSound("discover_spell")
hudPrint("You have forged an item, but the forge seems to be damaged now!")
   end
end
       
       caller:destroy()
       
    end

    function alcoveHelper()

       local alcove_clean_up = "alcove_"..getStatistic("play_time")
       spawn("timer", party.level, 1,1,1, alcove_clean_up )
          :setTimerInterval(0.01)
          :addConnector("activate", "alcove_script_5" , "remove_alcoveItems" ) 
          :activate()

    end
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply