Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

removeItem() not working? #6

Open
arkose opened this issue Jan 9, 2018 · 2 comments
Open

removeItem() not working? #6

arkose opened this issue Jan 9, 2018 · 2 comments

Comments

@arkose
Copy link

arkose commented Jan 9, 2018

Hello! I am finding that character.inventory.removeItem() does not work, at least for me. Here is a short story that should show that removeItem() doesn't work:

Home

You are standing in a grassy field.
<%if(!character.inventory.hasItem("sword")){%>
A sword lies here.
[[Take sword.|Take]]
<%}else{%>
You wield a sword.
[[Drop sword.|Drop]]
<%}%>

Take

<%character.inventory.addItem("sword");%>
You take the sword.
[[Continue.|Home]]

Drop

<%if(character.inventory.removeItem("sword")){%>
You put the sword down.
<%}else{%>
ERROR: character.inventory.removeItem("sword") failed!
character.inventory.indexOf("sword") is <%=character.inventory.items.indexOf("sword")%>.
<%}%>
[[Continue.|Home]]

This will print:

ERROR: character.inventory.removeItem("sword") failed! character.inventory.indexOf("sword") is -1.

@arkose
Copy link
Author

arkose commented Jan 9, 2018

Here is a fix:

character.inventory.removeItem = function (item)
{
 character.inventory.items.forEach(function(slot,index)
 {
  if(slot === null) {}
  else if(slot.tag === item)
  {
   character.inventory.remove(index);
   return true;
  }
 });
 return false;
};

@Longwelwind
Copy link
Owner

It should be fixed in the new version of Adventures, please reinstall the story format to see the change

Thanks for the issue !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants