Cant seem to make my equipment/invetory concept work!

been trying to make a working inventory system for a bit and i cant quite seem to get anything to work, like i want to make it so that some gear can boost other stats that other armors do not! i finally found one way i can do it but in testing it just keeps saying “unecpected identifier: chest”. does anyone know what i could do to fix the code to make it work? If i can make it so that it sets up this kinda stuff for an item as a test, then ill be able to make it work from there!


<<set $clothing to {
	head: {
    	name: "Gladiator helm",
        equipped: false,
        description: "A golden helm warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    }
    chest: {
        name: "Gladiator chestplate",
        equipped: false,
        description: "A golden chestplate warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    }
    	Arms: {
    	name: "Gladiator braces",
        equipped: false,
        description: "A pair of golden braces warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
    	Belt: {
    	name: "Gladiator belt",
        equipped: false,
        description: "A golden belt warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
   		legs: {
	    name: "Gladiator boots",
        equipped: false,
        description: "A pair of golden boots warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
}>>

You need commas between the object properties:

<<set $clothing to {
	head: {
    	name: "Gladiator helm",
        equipped: false,
        description: "A golden helm warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    },
    chest: {
        name: "Gladiator chestplate",
        equipped: false,
        description: "A golden chestplate warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    },
    	Arms: {
    	name: "Gladiator braces",
        equipped: false,
        description: "A pair of golden braces warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	},
    	Belt: {
    	name: "Gladiator belt",
        equipped: false,
        description: "A golden belt warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	},
   		legs: {
	    name: "Gladiator boots",
        equipped: false,
        description: "A pair of golden boots warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
}>>
3 Likes

Additional to what @svlin advised…

The information in your $clothing variable is what’s commonly knows as Stateless or Static, which basically means that once initialised it doesn’t change during playthrough…

Story variables are best suited storing Stateful or Dynamic information, like values that change during playthrough, or values supplied by the end-user (like a character name). This is because Story variable values are store in Progress History and Saves.

I suggest you move the data structure to the special setup variable, as its contents doesn’t get stored in History or Saves…

<<set setup.clothing to {
	head: {
    	name: "Gladiator helm",
        equipped: false,
        description: "A golden helm warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    }
    chest: {
        name: "Gladiator chestplate",
        equipped: false,
        description: "A golden chestplate warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
    }
    	Arms: {
    	name: "Gladiator braces",
        equipped: false,
        description: "A pair of golden braces warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
    	Belt: {
    	name: "Gladiator belt",
        equipped: false,
        description: "A golden belt warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
   		legs: {
	    name: "Gladiator boots",
        equipped: false,
        description: "A pair of golden boots warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
}>>

Which means that references like $clothing.head or $clothing['head'] would become setup.clothing.head and setup.clothing['head']

2 Likes

okay! would this allow me to edit the item variables then? like clothing.head.equipped or something like that? my idea would be that youd click a link in your inventory that would perform this function to equip the entire armorset or something, and then id make a seperate link to be able to unequip it (which may lead me to changing some things to say something like $muscle_equipment but i wanna see if i can avoud doing that for sake of simplicity)

Generally state changes like equipped would be handled external to the item definitions.

eg. an Array of “equipped” Item identifiers can be used..

1: Define the Stateless properties of each Item…

note: this would generally be done in the Story JavaScript area of a project.

setup.items = {
	'gladiator-helm': {
		name: "Gladiator helm",
		description: "A golden helm warn by the strongest of arena fighters, it grants +10 armor and muscle",
		stats: "<<set $muscle +=10>><<set $armor +=10>>",
		undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	},
	'gladiator-chestplate': {
		name: "Gladiator chestplate",
		description: "A golden chestplate warn by the strongest of arena fighters, it grants +10 armor and muscle",
		stats: "<<set $muscle +=10>><<set $armor +=10>>",
		undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
	'gladiator-braces': {
		name: "Gladiator braces",
        equipped: false,
        description: "A pair of golden braces warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
};

…but it can also be done in StoryInit using a <<set>> macro…

<<set setup.items to {
	'gladiator-helm': {
		name: "Gladiator helm",
		description: "A golden helm warn by the strongest of arena fighters, it grants +10 armor and muscle",
		stats: "<<set $muscle +=10>><<set $armor +=10>>",
		undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	},
	'gladiator-chestplate': {
		name: "Gladiator chestplate",
		description: "A golden chestplate warn by the strongest of arena fighters, it grants +10 armor and muscle",
		stats: "<<set $muscle +=10>><<set $armor +=10>>",
		undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
	'gladiator-braces': {
		name: "Gladiator braces",
        equipped: false,
        description: "A pair of golden braces warn by the strongest of arena fighters, it grants +10 armor and muscle",
        stats: "<<set $muscle +=10>><<set $armor +=10>>",
        undostats: "<<set $muscle -=10>><<set $armor -=10>>"
	}
}>>

2: Use the Item Definition’s identifier wherever the item needs to be referenced.

/* basic variable based */
<<set $buying to 'gladiator-braces'>>

/* non-slot based, using an Array */
<<set $carrying to ['gladiator-helm', 'gladiator-chestplate']>>
<<run $carrying.push('gladiator-chestplate')>>

/* slot-based, using a Generic Object */
<<set $body to {
	head: 'gladiator-helm',
	chest: 'gladiator-chestplate',
	arms: '',
	belt: '',
	legs: ''
}>>
<<set $body.arms to 'gladiator-braces'>>

3: Use the stored identifier to lookup the properties of the Item Definition.

/* when the identifier is stored in a basic variable */
Buying: <<= setup.items[$buying].name>>

/* when the identifier is stored in an Array element */
First item: <<= setup.items[$carrying[0]].name>>

/* when the identifier is stored in an Object property */
On head: <<= setup.items[$body.head].name>>

4: Un-reference items as need.

/* basic variable based */
<<set $buying to ''>>
or
<<unset $buying>>

/* when the identifier is stored in an Array element */
<<run $carrying.deleteFirst('gladiator-chestplate')>>
or
<<run $carrying.deleteAll('gladiator-chestplate')>>

/* when the identifier is stored in an Object property */
<<set $body.chest to ''>>