I was thinking just put a spell object on the setup object that contains all the user inputted details.Also have a string array of the spells to interact with it and fetch the details.
First StoryInit to initialize the spell object (all spells made will be put on the parent spells object). Also I initialize the spellbook array to hold just the string names of made spells.
<<set $spells = {}>> \ parent object for spells created
<<set $spellbook = []>>
Next, to be put in the Javascript section, is the code we pass so the details are stored on the setup object. I tweaked some code from Hiev I found to make this work.
setup.spellattributes = function (name, school, reach, effect) {
return {name: name, school: school, reach: reach, effect: effect};
};
Next our Spell Create passage (also start game here). We want to define the options the user can pick. I did 3 barebone properties here just to show you. The 3 temp arrays at the top will be used to populate the listboxes at the bottom that the player can pick. The only choice the user can type is the name. If the name entered is over 2 characters and spell name is not already used, a new spell will be created.
<h2>WELCOME TO SPELLMAKER!</h2>
<<set _spellschool = ["necromancy", "elemental", "restoration"]>>\
<<set _spellreach = ["short", "medium", "far"]>>\
<<set _spelleffect = ["damage", "poison", "heal"]>>\
SELECT SPELL SCHOOL:
<<listbox "_schoolselect" autoselect>>
<<optionsfrom _spellschool>>
<</listbox>>
SELECT SPELL REACH:
<<listbox "_reachselect" autoselect>>
<<optionsfrom _spellreach>>
<</listbox>>
SELECT SPELL EFFECT:
<<listbox "_effectselect" autoselect>>
<<optionsfrom _spelleffect>>
<</listbox>>
NAME SPELL:
<<textbox "_nameselect" "">>
<<button "Create spell">>
<<if $spellbook.includes(_nameselect)>>
<<replace #spelltest>>
You already have a spell named this!
<</replace>>
<<elseif _nameselect.length < 3>>\
<<replace #spelltest>>
The spell name must be at least two characters!
<</replace>>
<<else>>
<<set $spells[_nameselect] = new setup.spellattributes(_nameselect, _schoolselect, _reachselect, _effectselect)>>
<<set $spellbook.push(_nameselect)>>
<<replace #spelltest>>
_nameselect created!
<</replace>>
<</if>>
<</button>>
<span id = "spelltest">
</span>
[[Go to Spellbook|Spellbook]]
Finally the Spellbook page that shows all your spells in a listbox and when “cast spell” is pushed, the spell details are fetched. I just printed the details out to show its working, but in reality you would want to also put something like this on the combat page and do all the calculations here behind the scenes. Maybe someone far wiser than me can check this work to see if it accomplishes what you want
SPELLBOOK
<<listbox "_spellselect" autoselect>>
<<optionsfrom $spellbook>>
<</listbox>>
<<button "Cast spell">> /Do stuff to enemies or self, deduct mana, show a pic, etc...
<<replace #spelldetail>>
<<if _spellselect == "">>
No spell selected!!!
<<else>>
Spell cast: $spells[_spellselect].name
Spell effect: $spells[_spellselect].effect
Spell school: $spells[_spellselect].school
Spell effect: $spells[_spellselect].reach
<</if>>
<</replace>>
<</button>>
<span id = "spelldetail"></span>
[[Go to Spell Create|Spell create]]