0 votes
by (980 points)

Issue is that initially the item concatenates rather than adds and after unequipping and reequipping it works the way I want. I do not know how to fix this. Below I have tried explaining in more detail.

Example:

<<set $stats = [ 3, 10, 5, 7, 2, 6]>>

<<print $stats[0] + $str>>

<<print $stats[1] + $int>>

<<print $stats[2] + $con >>

<<print $stats[3] + $dex>>

<<print $stats[4] + $def>>

<<print $stats[5] + $char>>

 

$str, $int, $con, $dex, $def, $char all get their information from any item or spell. 

So if a necklace is equipped and it has 

"Strength" : 0,
  "Intelligence": 0,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 100,
  "Charisma" : 0,

Those values will be put inside the variable. The code I use for that  from my equipment menu to equip and add item stats to a variable is:

<<elseif $gear.Place eq $neck.Type and $neck.Wearing eq false>> <<link [Equip]>><<set $str += $gear.Strength>> <<set $int += $gear.Intelligence>> <<set $con += $gear.Constitution>> <<set $dex += $gear.Dexterity>> <<set $def += $gear.Defense>> <<set $char += $gear.Charisma>> <<set $gear.hasEquip = true>> <<set $head.Wearing eq true>> <</link>>

That is after there are some checks to see if neck has something already equipped. 

When 

<<print $stats[0] + $str>>

is printed. I get 30, $stats is pulling the 3 and $str the 0. Then later if you look at the defense which

<<print $stats[4] + $def>> I get 2100, 

In short what the stats look like before equiping an item,
Strength: 3

Intelligence: 10

Constitution: 5

Dexterity : 7

Defense : 2

Charisma: 6

When item is initially Equipped


Strength: 30

Intelligence: 100

Constitution 50

Dexterity  70

Defense :2100

Charisma: 60

 

When item is unequipped


Strength: 3

Intelligence: 10

Constitution: 5

Dexterity : 7

Defense : 2

Charisma: 6

 

When item is reequipped (What I want to happen to begin with)


Strength: 3

Intelligence: 10

Constitution: 5

Dexterity : 7

Defense : 102

Charisma: 6

 

Code for unequipping and taking away the stats added before:

<<if $gear.hasEquip == true>> Equipped <<link [UnEquip]>> <<set $str -= $gear.Strength>> <<set $int -= $gear.Intelligence>> <<set $con -= $gear.Constitution>> <<set $dex -= $gear.Dexterity>> <<set $def -= $gear.Defense>> <<set $char -= $gear.Charisma>> <<set $gear.hasEquip = false>> <</link>> 

1 Answer

0 votes
by (68.6k points)
selected by
 
Best answer
If you're getting string concatenations, then you're either making strings out of some of your numbers someplace or initalizing some as numeric strings in the first place.  Since it happens at the start, it's likely in some of your initializations.  I'd suggest looking for quotes where there shouldn't be any as a first step.
by (980 points)
I could not find what it was you were refering too. Or maybe I did not fully understand. I set the $str... etc off as empty variables because other wise they do not show up in the character sheet at all (just retried this to make sure I was not thinking of something else). I have the three passages posted that interact with each other. I have an inventory passage as well that works with nonequippable items. But that does not affect the stats and such at the moment.

StoryInit

 <<set $str = []>>
 <<set $int = []>>
 <<set $con = []>>
 <<set $dex = []>>
 <<set $def = []>>
 <<set $char = []>>
 
 <<set $inventory = []>>
 <<set $equipment = []>>
 <<set $head = {
    "Wearing" : false,
    "Type" : "head",
    }>>
<<set $neck = {
    "Wearing" : false,
    "Type": "neck",
    }>>
<<set $back = {
    "Wearing" : false,
    "Type": "back",
    }>>
<<set $backpack = {
    "Wearing" : false,
    "Type": "backpack",
    }>>    
<<set $mainHand = {
    "Wearing" : false,
    "Type": "mainhand",
    }>>
<<set $offHand = {
    "Wearing" : false,
    "Type": "offhand",
    }>>
<<set $armor = {
    "Wearing" : false,
    "Type": "armor",
    }>>    
<<set $belt = {
    "Wearing" : false,
    "Type": "belt",
    }>>
<<set $gloves = {
    "Wearing" : false,
    "Type": "gloves",
    }>>
<<set $legs = {
    "Wearing" : false,
    "Type": "legs",
    }>>
<<set $feet = {
    "Wearing" : false,
    "Type": "feet",
    }>>
<<set $ring = {
    "Wearing" : false,
    "Type": "ring",
    }>>

 
 <<set $strength = {
     "name" : "Strength",
    "description" : "determines how much damage one can do and if a boulder can be easily moved. Which is not suggesting that one should attempt to move a boulder."
    }>>
    
<<set $charisma = {
     "name" : "Charisma",
    "description" : "is how eaisy it is to sweet talk or get your way in a conversation."
    }>>    
    
<<set $defense = {
     "name" : "Defense",
    "description" : "is based of one's equipment and abilities. The better this is, the better it is for your health."
    }>>    
    
<<set $dexterity = {
     "name" : "Dexterity",
    "description" : "is all about how fast one moves. Whether it is how fast the blade swings or moving out of the way of falling rocks."
    }>>        
    
<<set $intelligence = {
     "name" : "Intelligence",
    "description" : "has never been a bad thing. This is about how to out wit one's opponent but also how much mana one has to ward off enemies."
    }>>             

<<set $constitution = {
     "name" : "Constitution",
    "description" : "reflects how healthy one is. So if there is a big gash across the stomach... well they are not very healthy, are they?."
    }>>    

 <<set $book0 = {
  "name": "Book of Beginnings",
  "type": "Book",
  "Useable": true,
  "hasItem":false,
  "description" : "A book that contains all information that one would know growing up in your city and amongst your people."
}>>

<<set $book1 = {
  "name": "Book of Fear",
  "type": "Book",
  "Useable": true,
  "hasItem": false,
  "description" : "A book that contains all that people feer."
}>>

<<set $necklace1 = {
  "Name" : "Amulet of Lineage",
  "Type" : "necklace",
  "Place" : "neck",
  "hasItem" : false,
  "hasEquip" : false,
  "Strength" : 0,
  "Intelligence": 0,
  "Constitution" : 0,
  "Dexterity" : 0,
  "Defense" : 100,
  "Charisma" : 0,
  "Description" : "Any decendant has a necklace that is a claim to their bloodline. This one has a symbol of a falcon's head."
}>>

 

Equipment Page

<<for $e = 0; $e < $equipment.length; $e++>>
<<set $gear = $equipment[$e]>>
<<print $gear.Name>>
<<print $gear.Description>>

<<if $gear.hasEquip == true>> Equipped <<link [UnEquip]>> <<set $str -= $gear.Strength>> <<set $int -= $gear.Intelligence>> <<set $con -= $gear.Constitution>> <<set $dex -= $gear.Dexterity>> <<set $def -= $gear.Defense>> <<set $char -= $gear.Charisma>> <<set $gear.hasEquip = false>> <</link>>

<<elseif $gear.Place eq $neck.Type and $neck.Wearing eq true>> You need to unequip the current item resting around your neck. Sorry but more than one necklace interfers with each other's abilities. Best to be safe rather than to end up like Rob.   

<<elseif $gear.Place eq $neck.Type and $neck.Wearing eq false>> <<link [Equip]>><<set $str += $gear.Strength>> <<set $int += $gear.Intelligence>> <<set $con += $gear.Constitution>> <<set $dex += $gear.Dexterity>> <<set $def += $gear.Defense>> <<set $char += $gear.Charisma>> <<set $gear.hasEquip = true>> <<set $head.Wearing eq true>> <</link>>
<</if>>
<</for>>

 

Character Sheet

<<return>>

<<nobr>>Race:
<<if def $race>>
$race
<<else>>
Please return to choose your race
<</if>><</nobr>>

<<nobr>>Gender:
<<if def $gender>>
$gender
<<else>>
Please return to choose your gender.
<</if>><</nobr>>

<<nobr>>Age:
<<if def $age>>
$age years
<<else>>
Please return to choose your age.
<</if>><</nobr>>

<<nobr>>Skin Color:
<<if def $skinColor>>
$skinColor
<<else>>
Please return to choose your skin color.
<</if>><</nobr>>

<<nobr>>Hair Color:
<<if def $hairColor>>
$hairColor
<<else>>
Please return to choose your hair color.
<</if>><</nobr>>

<<nobr>>Hair Style:
<<if def $hairStyle>>
$hairStyle
<<else>>
Please return to choose your hair style.
<</if>><</nobr>>

Stats:
<<if def $stats>>
<div class="hover">
<<nobr>><<link "Strength">>
<</link>>
<span class="hoverblock">
$strength.description
</span><</nobr>></div>: <<print $stats[0] + $str>>
<div class="hover"><<nobr>>
<<link "Intelligence">>
<</link>>
<span class="hoverblock">
$intelligence.description
</span><</nobr>></div>: <<print $stats[1] + $int>>
<div class="hover"><<nobr>>
<<link "Constitution">>
<</link>>
<span class="hoverblock">
$constitution.description
</span>
<</nobr>></div>: <<print $stats[2] + $con >>
<div class="hover"><<nobr>>
<<link "Dexterity">>
<</link>>
<span class="hoverblock">
$dexterity.description
</span>
<</nobr>>
</div>: <<print $stats[3] + $dex>>
<div class="hover"><<nobr>>
<<link "Defense">>
<</link>>
<span class="hoverblock">
$defense.description
</span>
<</nobr>>
</div>: <<print $stats[4] + $def>>
<div class="hover"><<nobr>>
<<link "Charisma">>
<</link>>
<span class="hoverblock">
$charisma.description
</span>
<</nobr>> </div>: <<print $stats[5] + $char>>
<<else>> Please return to character creation
<</if>>
by (159k points)

Your issue is caused by the fact that you are initialising your $str, $int, $con, $dex, $def, and $char story variables as empty Arrays, which you later try to add a numeric value to using the mathematical plus operator.

<<set $str = []>>

<<set $str += $gear.Strength>>
/* the above Strength property equals a numeric value like 0 (zero) */

Because the value of $str and $gear.Strength are of different data types (Array and Integer), and because you can't add an element to an Array via the plus operator, the JavaScript enviroment needs to convert both values to the same data type.

It does these by first converting the empty Array in $str to an empty String "", it next converts the 0 (zero) to a "0" String, and finally it concatenates the two values together to end up with a "0" String which it assigns to the $str story variable.

After this every numeric you add to the $str variable is also converted to a String value before being concatenated to the current String value within that variable.

You need to initialise your $str, $int, $con, $dex, $def, and $char story variables as numeric 0 (zero)

<<set $str = 0>>
<<set $int = 0>>
<<set $con = 0>>
<<set $dex = 0>>
<<set $def = 0>>
<<set $char = 0>>

 

by (980 points)
Awesome! Thank you, that makes sense and changing it over worked!

I do not really know what I am doing. I am watching a lot of tutorials and grabbing code. Then changing it to fit what I want and spend hours trying to find a missing comma... well spend hours to fix the problem and sometimes it is a missing < or , or something. Lol.

 

Thank you both!

 

-Assira
...