Page 1 of 2
crash
Posted: Thu Jul 03, 2014 12:14 am
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:
[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
Re: crash
Posted: Thu Jul 03, 2014 4:23 am
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 .
Re: crash
Posted: Thu Jul 03, 2014 3:44 pm
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).
Re: crash
Posted: Thu Jul 03, 2014 8:37 pm
by Isaac
As minmay has suggested. This is better.
(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
Re: crash
Posted: Fri Jul 04, 2014 7:41 am
by msyblade
Absolutely the answer. 0.1 delay between scripts should be fine
Re: crash
Posted: Fri Jul 04, 2014 4:33 pm
by bongobeat
thanks for your answers.
Yes I see now. I will try some, thanks
Isaac wrote:As minmay has suggested. This is better.
(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

Re: crash
Posted: Sat Jul 05, 2014 9:30 am
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)

:
the destroy/spawn start even if not the correct number of items are put:
eg:
here is the script:
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.
Re: crash
Posted: Sat Jul 05, 2014 7:00 pm
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.
Re: crash
Posted: Sun Jul 06, 2014 7:48 am
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.
Re: crash
Posted: Sun Jul 06, 2014 6:26 pm
by bongobeat
ho many thanks!
this works fine!
(you guys are realy incredible!)
here is the final script if someone want's it:
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