Error in trait, please help

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Error in trait, please help

Post by Drakkan »

can somebody please fix what is wrong with my script ? It crash game when I right-click on empty hand of any champion

mod_assets/scripts/drakkantraits.lua:189: attempt to index local 'weapon' (a nil value)
stack traceback:
mod_assets/scripts/drakkantraits.lua:189: in function 'onComputeCooldown'
[string "MeleeAttack.lua"]: in function 'start'
[string "Champion.lua"]: in function 'attack'
[string "AttackPanel.lua"]: in function 'select'
[string "AttackPanel.lua"]: in function 'drawItemSlot'
[string "AttackPanel.lua"]: in function 'updateAttackButtons'
[string "AttackPanel.lua"]: in function 'update'
[string "AttackPanel.lua"]: in function 'update'
[string "Gui.lua"]: in function 'draw'
[string "GameMode.lua"]: in function 'update'
[string "Grimrock.lua"]: in function 'display'
[string "Grimrock.lua"]: in main chunk



defineTrait{
name = "grandmaster_sword",
uiName = "Sword slasher",
icon = 3,
description = "Any sword attack is 20% faster.",
onComputeCooldown = function(champion, weapon, attack, attackType, level)
if weapon:hasTrait("sword") or weapon:hasTrait("sword") then return 0.833 --row 189
end
end,
}
Breath from the unpromising waters.
Eye of the Atlantis
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Error in trait, please help

Post by alois »

Try with "if weapon and weapon:hasTrait("sword")" etc...

Alois :)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Error in trait, please help

Post by akroma222 »

Pretty sure it should be...
SpoilerShow

Code: Select all

defineTrait{
name = "grandmaster_sword",
uiName = "Sword slasher",
icon = 3,
description = "Any sword attack is 20% faster.",
onComputeCooldown = function(champion, weapon, attack, attackType, level)
          if level > 0 then
                        if weapon and  weapon:hasTrait("sword") then 
                                       return 0.833 
                        end
           end
end,
}
(not tested) - remember to check level > 0 and then weapon ~= nil (or just 'if weapon then)
If you dont check these the game can crash at the party creation screen while picking traits
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Error in trait, please help

Post by Dunkler »

Do cooldown buffs stack?

I mean if you have different traits that grant a bonus to cooldown..do they stack or do they multiply? How does it work?
minmay
Posts: 2789
Joined: Mon Sep 23, 2013 2:24 am

Re: Error in trait, please help

Post by minmay »

onComputeCooldown stacks multiplicatively and doesn't work on spell casts. cooldown_rate increases or decreases are added together before applying, instead of applying separately, and do work on spell casts.
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.
Dunkler
Posts: 73
Joined: Thu Jul 10, 2014 3:20 pm

Re: Error in trait, please help

Post by Dunkler »

Thank you!
Post Reply