- Jun 15, 2017
- 238
- 588
I'm trying to use a stat system for NPC's in a twine sugarcube game. Snippet of NPC code:
The code I have works when I call on it to change the mc's stats using
I already defined the NPCstat array (shown below) So it has to be something to do with the locating that array or something. Any help? I'll attach the HTML if anyone wants to see all of the code. The parts I'm having problems with is in "NPC System" and "Stat Widgets".
Code:
<<widget "AddStat">>
<<set _npc = $args[0]>>
<<set _stat = $args[1]>>
<<set _app = $args[2]>>
<<set _limit = $args[3]>>
<<if _npc != "mc">>
<<if _stat == "corruption">>
<<if _limit == 0>>
<<set $NPCstat[_npc].corruption += _app>>
<b><i>$NPCstat[_npc].name's corruption was increased _degree</i></b>
<<elseif $NPCstat[_npc].corruption < (_limit - _app)>>
<<set $NPCstat[_npc].corruption += _app>>
<b><i>$NPCstat[_npc].name's corruption was increased _degree</i></b>
<<elseif $NPCstat[_npc].corruption < _limit>>
<<set $NPCstat[_npc].corruption = _limit>>
<b><i>$NPCstat[_npc].name's corruption was increased _degree</i></b>
<<else>>
<b><i>This action can't increase $NPCstat[_npc].name's corruption further</i></b>
<</if>>
<</if>>
<</if>>
<<AddStat mc "willpower" 5 100>>
, but when I call an NPC stat change using <<AddStat 0 "love" 5 100>>
. I get this error " Error: <<AddStat>>: error within widget contents (Error: <<if>>: bad conditional expression in <<elseif>> clause (#1): Cannot read property '0' of undefined)
".I already defined the NPCstat array (shown below) So it has to be something to do with the locating that array or something. Any help? I'll attach the HTML if anyone wants to see all of the code. The parts I'm having problems with is in "NPC System" and "Stat Widgets".
Code:
<<set $NPCstat = []>>
/* Mother */
<<set $NPCstat[0] = {
name: "Alexis",
lastname: "$mc.lastname",
realname: "Alexis Fawx",
corruption: 0,
obedience: 0,
love: 30,
lust: 30
style: "Mother",
label: "Mother",
}>>
Last edited: