Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function spellLookup(event)
- {
- if (!searchingForSpell) //do not do two searches at the same time
- {
- var spellStartWithMatches = [];
- var spellMatches = [];
- searchingForSpell = true;
- for (var i = 0, l = spells.length; i < l; i++)
- {
- if (spells[i].name.toLowerCase().startsWith(event.target.value.toLowerCase()))
- {
- spellStartWithMatches.push({"name" : spells[i].name, "index" : i});
- }
- else if (spells[i].name.toLowerCase().includes(event.target.value.toLowerCase()))
- {
- spellMatches.push({"name" : spells[i].name, "index" : i});
- }
- }
- searchingForSpell = false;
- console.log(JSON.stringify(spellStartWithMatches));
- console.log(JSON.stringify(spellMatches));
- //display spell matches in a list below the + add new spell +
- //on spell click select spell by the index, and add it to the slot
- //don't be a dick, do not iterate everything everytime
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement