alkku15 Posted May 18, 2018 Share Posted May 18, 2018 how does this work? how can i get some number out of this: yes am a noobie, thanks! public int getCurrentDrinkLevel() { RS2Widget widget = getWidgets().get(202, 1, 9); if (widget != null && widget.isVisible() && widget.getMessage() != null) return Integer.parseInt(widget.getMessage().replace(",", "")); return 0; } Quote Link to comment Share on other sites More sharing options...
yfoo Posted May 19, 2018 Share Posted May 19, 2018 (edited) This method reads a RS2Widget for a message, a widget is a UI component in runescape, in this case the widget to be read is the absorption widget in NMZ. To read a widget you must first get an instance of it. The line RS2Widget widget = getWidgets().get(202, 1, 9) does that. The parameters in the get method are .get(rootID, child+ ID, child++ ID). Every widget can be identified by these 3 parameters, in some cases it can be identified by 2. It is better to obtain widgets through only the rootID through an API method that can identify widgets via a unique sprite, text, options, ect because child IDs may change over game updates. However I have use the above snippet in my own code for several months and have not seen IDs change yet. If you are just learning widgets don't bother with the better practice and just get it working first. This image shows an example of the absorption widget's ids and the widget itself's instance variables. The message instance variable contains the player's absorption level. https://imgur.com/8U5TKE6 Edited May 19, 2018 by PayPalMeRSGP Quote Link to comment Share on other sites More sharing options...
alkku15 Posted May 19, 2018 Author Share Posted May 19, 2018 (edited) 4 hours ago, PayPalMeRSGP said: This method reads a RS2Widget for a message, a widget is a UI component in runescape, in this case the widget to be read is the absorption widget in NMZ. To read a widget you must first get an instance of it. The line RS2Widget widget = getWidgets().get(202, 1, 9) does that. The parameters in the get method are .get(rootID, child+ ID, child++ ID). Every widget can be identified by these 3 parameters, in some cases it can be identified by 2. It is better to obtain widgets through only the rootID through an API method that can identify widgets via a unique sprite, text, options, ect because child IDs may change over game updates. However I have use the above snippet in my own code for several months and have not seen IDs change yet. If you are just learning widgets don't bother with the better practice and just get it working first. This image shows an example of the absorption widget's ids and the widget itself's instance variables. The message instance variable contains the player's absorption level. https://imgur.com/8U5TKE6 thanks. i already knew this, i know the basics and i know how to use widgets (for example interacting with them etc etc.), BUT how can i use this snippet what i posted in my code? where do i put it? do i need to do something like if (getCurrentDrinkLevel > 100) ??? thats what i ment... or do i need to put my absorption level number between these " "'s in the snippet? *i tried something stupid like this: if (widget.getMessage().contains("970")) { inventory.interact("Drink", "Absorption potion(4)", "Absorption potion(3)", "Absorption potion(2)", "Absorption potion(1)"); } Edited May 19, 2018 by alkku15 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted May 19, 2018 Share Posted May 19, 2018 14 hours ago, alkku15 said: thanks. i already knew this, i know the basics and i know how to use widgets (for example interacting with them etc etc.), BUT how can i use this snippet what i posted in my code? where do i put it? do i need to do something like if (getCurrentDrinkLevel > 100) ??? thats what i ment... or do i need to put my absorption level number between these " "'s in the snippet? *i tried something stupid like this: if (widget.getMessage().contains("970")) { inventory.interact("Drink", "Absorption potion(4)", "Absorption potion(3)", "Absorption potion(2)", "Absorption potion(1)"); } It's clear that the method you've posted returns an Integer, so you'd check getCurrentDrinkLevel() > 100. The fact you can't figure that out though suggests to me you need to go and read up a little bit more on basic variables / methods. Quote Link to comment Share on other sites More sharing options...
alkku15 Posted May 21, 2018 Author Share Posted May 21, 2018 On 5/19/2018 at 10:03 PM, HeyImJamie said: It's clear that the method you've posted returns an Integer, so you'd check getCurrentDrinkLevel() > 100. The fact you can't figure that out though suggests to me you need to go and read up a little bit more on basic variables / methods. ye ikr im a noob at coding but why doesn't this work? i drank abs all the way to 450, then ran the script for 1min didnt do anything if (getCurrentDrinkLevel() < 500) { inventory.interact("Drink", "Absorption potion(4)", "Absorption potion(3)", "Absorption potion(2)", "Absorption potion(1)"); } Quote Link to comment Share on other sites More sharing options...
yfoo Posted May 21, 2018 Share Posted May 21, 2018 45 minutes ago, alkku15 said: ye ikr im a noob at coding but why doesn't this work? i drank abs all the way to 450, then ran the script for 1min didnt do anything if (getCurrentDrinkLevel() < 500) { inventory.interact("Drink", "Absorption potion(4)", "Absorption potion(3)", "Absorption potion(2)", "Absorption potion(1)"); } The potions are called Absorption(4). not Absorption potion(4). You have ur strings wrong. Quote Link to comment Share on other sites More sharing options...