Page 1 of 1
[FIXED] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Nov 05, 2014 6:38 pm
by Lark
The following object, when destroyed, blows up and damages the party... and then the editor/game immediately hang. This was my first object I created for LoG1 and I wanted to use it in LoG2. Prozail helped convert it, but alas it locks up everything when it dies.
Is this a bug or is something wrong with the object? Thanks,
-Lark
Code: Select all
defineObject {
name = "exploding_barrel_block",
baseObject = "barrel_crate_block",
components = {
{
class = "Health",
name ="health",
health = 30,
onDie = function(c)
local i, j
for i = -1, 1 do
for j = -1, 1 do
spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
end
end
end
},
},
}
(Reposted from dormant thread.)
Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Nov 05, 2014 7:06 pm
by Prozail
Looks like it hangs only if the ENTIRE party dies. If you do damage with for instance a fireball, that some survies, it works., maybe try a delayedCall to not have the party die in the same "gameframe", not tested myself.
My second suggestion is toying with the tiledamager-component
Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Nov 05, 2014 7:09 pm
by JohnWordsworth
I think the problem is that the fireburst is spawning immediately, which is then doing more damage to the health component, which is calling onDie again, which is spawning more fireburst... This loop continues until the game crashes.
SO...
You have two options.
1. Spawn a fireburst on the 8-spaces around the barrel but not on the barrel.
Code: Select all
defineObject {
name = "exploding_barrel_block",
baseObject = "barrel_crate_block",
components = {
{
class = "Health",
health = 30,
onDie = function(c)
local i, j;
for i = -1, 1 do
for j = -1, 1 do
if i ~= 0 or j ~= 0 then
spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
end
end
end
end
}
}
}
2. Set a flag on the component in the onDie function. At the start of the function, if that flag is already set, then you return doing nothing more (stop the infinite loop). This appears to work (which is cool), but I don't know what the policy is on setting random variables on components like this (it seems to work fine - but is it meant too?).
Code: Select all
defineObject {
name = "exploding_barrel_block",
baseObject = "barrel_crate_block",
components = {
{
class = "Health",
health = 30,
onDie = function(c)
if ( c.property ~= nil ) then
--print("BLOCKED")
return
end
c.property = 1;
local i, j;
for i = -1, 1 do
for j = -1, 1 do
spawn("fireburst", c.go.level, c.go.x + i, c.go.y + j, 0, c.go.elevation)
end
end
end
}
}
}
Both of these solutions appear to work in the editor for me, whereas I got a crash with your original code.
Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Nov 05, 2014 7:13 pm
by Prozail
Thank you John.. you just answered another question I had
![Wink ;)](./images/smilies/icon_e_wink.gif)
Re: [Bug?] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Nov 05, 2014 7:26 pm
by Lark
Perfect, thank you. Why do I expect old (lazy) programming from LoG1 to work on LoG2? Hey, it was my first LUA! And should I change history? Won't the Smithsonian object? Good programming will always win out. Speaking of which, I should probably do boundary checking... Thank you John! -Lark
Re: [FIXED] Editor Hangs: Obj > Die > Spell > Damage Party
Posted: Wed Jun 24, 2015 11:10 pm
by Kuro01
I made one that spawns rats. I'm new at this lots of fun.It works.Not sure if everything in there is needed.
Code: Select all
defineObject{
name = "exploding_barrel_rat_swarm",
baseObject = "base_obstacle",
components = {
{
class = "Model",
model = "assets/models/env/barrel_crate_block.fbx",
},
{
class = "Obstacle",
hitSound = "barrel_hit",
hitEffect = "hit_wood",
},
{
class = "Health",
health = 50,
immunities = { "poison" },
spawnOnDeath = "barrel_crate_block_broken",
onDie = function(self)
for i = 1, math.random(2,3) do
local obj = self.go:spawn("rat_swarm")
local pos = obj:getWorldPosition()
local spread = 1.5
pos.x = pos.x + (math.random() - 0.5) * spread
pos.z = pos.z + (math.random() - 0.5) * spread
obj:setWorldPosition(pos)
end
end,
},
{
class = "Sound",
sound = "barrel_die",
},
},
editorIcon = 260,
}