Page 1 of 1

crash on the mouseitem

Posted: Sun Mar 20, 2016 4:41 pm
by bongobeat
hello all,

I got a crash when breaking a breakable object and wonder if someone can help about that:
I was holding an item on the mouse which use a special script while tryin to break the object, here is the screen error:
SpoilerShow
Image
I guess this is because the kind of item has some conditions when used and equipped in both hands. and I suppose that I need to add a condition for the mouse item things. Can anybody help about that?

this is the script used by the item:
SpoilerShow

Code: Select all

		onAttack = function(self, champion, slot, chainIndex)
----
       local ammo1 = champion:getItem(1)
       local ammo2 = champion:getItem(2)
	if ammo1 and ammo2 then
       if ammo1.go.name == "ion_gun" and ammo2.go.name == "power_recharge"
       or ammo2.go.name == "ion_gun" and ammo1.go.name == "power_recharge" then
          ----
          local ion = spawn("ion_object",party.level,party.x,party.y,party.facing,party.elevation)
          ion.projectile:setIgnoreEntity(party)

          -- Set cast by champion so that experience is awarded for kills.
          local ord = champion:getOrdinal()
           ion.projectile:setCastByChampion(ord)

          -- Simulate the position of a player-cast spell.
          local left = nil
          for i = 1,4 do
             if party.party:getChampion(i):getOrdinal() == ord then
                left = i == 1 or i == 3
                break
             end
          end
          local wpos = party:getWorldPosition()
          local dx = nil
          local dz = nil
          if party.facing == 0 then
             dx = left and -0.1 or 0.1
             dz = -1
          elseif party.facing == 1 then
             dz = left and 0.1 or -0.1
             dx = -1
          elseif party.facing == 2 then
             dx = left and 0.1 or -0.1
             dz = 1
          else -- party.facing == 3
             dz = left and -0.1 or 0.1
             dx = 1
          end

          ion:setWorldPosition(vec(wpos[1]+dx,wpos[2]+1.35,wpos[3]+dz))
       end
    end
end

Re: crash on the mouseitem

Posted: Sun Mar 20, 2016 9:33 pm
by minmay
Why are you posting an onAttack hook instead of the onComputeCooldown hook that the error actually occurred in? Nobody can help you if you don't post the onComputeCooldown hook.

Re: crash on the mouseitem

Posted: Thu Mar 31, 2016 5:56 pm
by bongobeat
sorry I didnt thought about the onComputeCooldown, since I thought that this error comes from the items definition:


here is the onComputeCooldown I use in a trait:

Code: Select all

defineSkill{
	name = "faster",
	uiName = "Toorum's Disciple",
	priority = 190,
	icon = 108,
	description = "As a fighter you know that speed and dexterity are crucial. You are following Toorum's teachings to learn an incredible speed. Each level spent increase your dexterity by 1. At 3rd level your cooldown are decreased by 25%. At 5th level you learn the thunderstruck trait.",
	onRecomputeStats = function(champion, level)
		if level > 0 then
		champion:addStatModifier("dexterity", 1)
		end
	end,
	traits = { [3] = "faster3", [5] = "faster5" },
}

defineTrait{
	name = "faster3",
	uiName = "Quick as the wind",
	icon = 108,
	description = "Your are teached into the Rite of the Wind.  Your cooldown is decreased by 25%.",
	onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then return 0.8 end
	end,
}

defineTrait{
	name = "faster5",
	uiName = "Thunderstruck",
	icon = 108,
	description = "Your have reached the grandmastery and gain the Thunderstruck trait. All cooldowns are halved.",
	onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then return 0.5 end
	end,
}

Re: crash on the mouseitem

Posted: Thu Mar 31, 2016 7:55 pm
by minmay
Those are not the relevant onComputeCooldown hooks because they never try to index a variable called "weapon"...please post ALL your onComputeCooldown hooks in mod_assets/scripts/traits.lua. Or, better, post the one that includes line 149.

Re: crash on the mouseitem

Posted: Sat Apr 02, 2016 8:58 am
by bongobeat
aargh!
I forgot this one! :roll:

ok, here is the whole trait, the line 149 starts at "icon = 43," :
SpoilerShow

Code: Select all

defineTrait{
	name = "mweapon_mastery",
	uiName = "Ancient Weapons Master",
	icon = 43,
	description = "As a master in ancient weapons, you know how to recharge them faster. All attacks with that type of weapon are 25% faster.",
    onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if level > 0 then
          if weapon:hasTrait("modern") or weapon:hasTrait("modern") then return 0.8 end
	end
end,

}

Re: crash on the mouseitem

Posted: Sat Apr 02, 2016 9:05 pm
by Isaac
It should probably be written: weapon.item:hasTrait("modern")

Code: Select all

if weapon.item:hasTrait("modern") or weapon.item:hasTrait("modern") then return 0.8 end

Re: crash on the mouseitem

Posted: Sat Apr 02, 2016 10:23 pm
by minmay
No, that's not the issue, weapon is always either an ItemComponent or nil. The issue is that you are not checking whether weapon is nil; you'll get a crash with unarmed attacks. It should be:

Code: Select all

onComputeCooldown = function(champion, weapon, attack, attackType, level)
  if weapon and level > 0 then
    if weapon:hasTrait("modern") then return 0.8 end
  end
end,

Re: crash on the mouseitem

Posted: Sun Apr 03, 2016 7:40 pm
by bongobeat
thanks a lot, works very well :D