Twine Version: 2.8.1 Story Format: Sugarcube 2.36.1
[also choose a Story Format tag above]
Hello! I am writing a widget which determines the nature of enemy to determine if weapon does any damage. For example, non-silver does not damage undead. And this widget is called inside the sword attack widget. Can we use _args[0] again inside such nested widget?
But I think that maybe I should do it somehow simpler.
Thanks in advance!
StoryInit:
<<set $enmNature=1; $enmGiant=1; $enmElem=1; $enmMod=1>>
/*max enmNature=1, max enmGiant=1.5, max enmElem=1.5*/
/*set weapon*/
<<set $sword={type: "weapon1h", wtype: "sword", name:"Š¶ŠµŠ»ŠµŠ·Š½ŃŠ¹ Š¼ŠµŃ", atk: 70, cost:25, ench: 0, enchType: "water", material: "iron"}>>
/*set enemy*/
<<set $enm to {
name: "ŃŠŗŠµŠ»ŠµŃ-Š²Š¾ŠøŠ½", lvl: 4, sp: 4,
streng: 6, dex: 0.3, intel: 4, wisd: 2,
hp: 340, maxhp: 340, mp: 100, maxmp: 100, stam: 100, maxstam: 100, def: 190, atk: 250, atkMax: 250, atkname: "Š½Š°Š½Š¾ŃŠøŃ ŃŠ“Š°Ń Š¼ŠµŃŠ¾Š¼", atkrange: 3,
exper: 400, slash: 1.2, pierce: 1, smash: 0.9, hack: 1.1, effect: "none", effDur: 0, water: 0.95, earth: 0.8, fire: 1.1,
nature: "undead", giant: false, elem: "none"
}>>
/*Widget passage*/
/*calculate enemy modificator enmMod*/
<<widget "EnmWeak">>
<<if _args[0] and _args[1]>>/*if defined temporary variables (elements of array) _args[0] - weapon, _args[1] - enemy*/
<<capture _args[0], _args[1]>>/*keep temporary variables in memory*/
<<if _args[0].material=="silver">>
<<if _args[1].nature=="undead">><<set $enmNature=1>><</if>>
<<elseif _args[0].material!="silver">>
<<if _args[1].nature=="undead">><<set $enmNature=0>><</if>>
<</if>>
<<if (_args[0].wtype=="spear") and (_args[1].giant==true)>>
<<set $enmGiant=1.5>>
<</if>>
<<if _args[1].elem!= _args[0].enchType>><<set $enmElem=1.5>><</if>>
<<set $enmMod=$enmNature*$enmGiant*$enmElem>>
<</capture>>
<</if>>/*end all ifs*/
<</widget>>
/*sword attack widget*/
<<widget "SwordAtkYourHack">>
<<if $singleE is true>><<if _args[0]>>
<<capture _args[0]>>
<<AtkPr $you.swordSkill>>
<<EnmWeak $sword $enm>>/*pass enemy and weapon to widget to calculate enmMod*/
<<set $you.currAtk=Math.trunc($enm.hack*($you.swordSkill+$you.meleeSkill)*(_args[0].atk+_args[0].ench)*(1-$enm.dex)*$atk_prob*$enmMod)>>/*calculate attack of sword with modificator enmMod*/
<<set $you.currHit=$you.currAtk-$enm.def>>
<<if $you.currHit gt 0>><<set $enm.hp-=$you.currHit>>
<<else>><<set $enm.hp-=$you.streng>>
<</if>>
<<SwordSkillProgress>>
<<MeleeSkillProgress>>
<<set $turn to "enemy">><<set $nturn+=1>>
<<set $log to "attack">><<addmins 5>>
<</capture>>
<</if>><</if>>
<</widget>>