dorukanji 0 Share Posted November 29, 2016 Is there a simple way to do this. String itemName = "Bronze sword" itemName --> ??? --> itemID Link to comment Share on other sites More sharing options...
dorukanji 0 Author Share Posted November 29, 2016 not currently located anywhere I am taking input as a String, eg. "Bronze sword", and then checking GE API, which uses ID, for its price I can find the ID from the Item class but just wondering if there was a way to get ID from name without the actual Item, seeing as Item only has ID constructor I have a workaround but just wondering. I'm guessing it doesn't work too well if two items have different ID but the same name. Link to comment Share on other sites More sharing options...
slasso 27 Share Posted November 29, 2016 Well, you can put the items in your own Map object. I think item names are unique (I can't think of any GE items with the same names but are different), so a Map<String, Integer> with name as the key and the id as the value could work. To make such a Map, you can take this JSON of all the items https://rsbuddy.com/exchange/names.json, iterate over the keys (the ids), take the name, put it in your Map as the key and take the current id key and put it as the value. Link to comment Share on other sites More sharing options...
Cardozz 46 Share Posted November 29, 2016 You don't even need a map. You could also make an Enum: BRONZE_SWORD("Bronze sword", <ID>); Then just make the constructor for it and grab the ID. ID's can be found on the internet. I don't think you can grab the ID's from the game without the actual item. Manually doing this for each item on RS will be a huge load of work, so Slasso's solution is way better! Link to comment Share on other sites More sharing options...
Dogerina 330 Share Posted November 29, 2016 Well, you can put the items in your own Map object. I think item names are unique (I can't think of any GE items with the same names but are different), so a Map<String, Integer> with name as the key and the id as the value could work. To make such a Map, you can take this JSON of all the items https://rsbuddy.com/exchange/names.json, iterate over the keys (the ids), take the name, put it in your Map as the key and take the current id key and put it as the value. Names are not unique, multiple items have the same name (For example, noted version of an item has the same name as the unnoted verson). Link to comment Share on other sites More sharing options...
slasso 27 Share Posted November 29, 2016 not currently located anywhere I am taking input as a String, eg. "Bronze sword", and then checking GE API, which uses ID, for its price I can find the ID from the Item class but just wondering if there was a way to get ID from name without the actual Item, seeing as Item only has ID constructor I have a workaround but just wondering. I'm guessing it doesn't work too well if two items have different ID but the same name. Here you go. I iterated through all the items and auto generated the puts you need. Some item names have multiple ids so I have a custom put method that handles that and adds it to the list. http://pastebin.com/UM9c9rU5 edit: make the public methods in this class static. In your main class, call Items.initMap() in the onStart() and you can make a Map variable, Map<String, Integer> itemsMap = Items.getMap(). Then you can do what you wanted originally. int id = itemsMap.get("Bronze sword"); Names are not unique, multiple items have the same name (For example, noted version of an item has the same name as the unnoted verson). Map which has a List<Integer> as value works fine Link to comment Share on other sites More sharing options...
dorukanji 0 Author Share Posted November 30, 2016 Here you go. I iterated through all the items and auto generated the puts you need. Some item names have multiple ids so I have a custom put method that handles that and adds it to the list. http://pastebin.com/UM9c9rU5 edit: make the public methods in this class static. In your main class, call Items.initMap() in the onStart() and you can make a Map variable, Map<String, Integer> itemsMap = Items.getMap(). Then you can do what you wanted originally. int id = itemsMap.get("Bronze sword"); Map which has a List<Integer> as value works fine You're a real hero Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.