Sana Posted May 6, 2019 Share Posted May 6, 2019 (edited) Working on my first ever script, got it complete after about 24 hours but I'm stuck on the very last step which is to trade a player the items I've acquired. The `if` statement is failing every time, even when I'm less than 5 squares from the player. It's as if the player is invisible from the bot. This is what I'm doing: private boolean tradePlayer() { Player player = getPlayers().closest(PLAYER_NAME); if (player != null && player.interact("Trade with")) { Sleep.sleepUntil(() -> getTrade().isCurrentlyTrading(), 60000, random(100, 200)); getTrade().offerAll(ITEM_ID); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().isSecondInterfaceOpen(), 60000, random(100, 200)); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().didOtherAcceptTrade(), 60000, random(100, 200)); return true; } return false; } Any idea why this script function isn't trading the player? Edited May 6, 2019 by Lansana Camara Quote Link to comment Share on other sites More sharing options...
FuryShark Posted May 6, 2019 Share Posted May 6, 2019 (edited) It works for me, have you remembered to click refresh on osbot? also try adding log() s to see where its getting to. also have you made sure the username is spelt correctly Edited May 6, 2019 by FuryShark Quote Link to comment Share on other sites More sharing options...
Naked Posted May 6, 2019 Share Posted May 6, 2019 1 hour ago, Lansana Camara said: Working on my first ever script, got it complete after about 24 hours but I'm stuck on the very last step which is to trade a player the items I've acquired. The `if` statement is failing every time, even when I'm less than 5 squares from the player. It's as if the player is invisible from the bot. This is what I'm doing: private boolean tradePlayer() { Player player = getPlayers().closest(PLAYER_NAME); if (player != null && player.interact("Trade with")) { Sleep.sleepUntil(() -> getTrade().isCurrentlyTrading(), 60000, random(100, 200)); getTrade().offerAll(ITEM_ID); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().isSecondInterfaceOpen(), 60000, random(100, 200)); getTrade().acceptTrade(); Sleep.sleepUntil(() -> getTrade().didOtherAcceptTrade(), 60000, random(100, 200)); return true; } return false; } Any idea why this script function isn't trading the player? You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } } Quote Link to comment Share on other sites More sharing options...
Sana Posted May 6, 2019 Author Share Posted May 6, 2019 1 hour ago, Naked said: You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } } Why is this? I come from a GoLang/JavaScript/PHP background, and this is allowed in those C-based languages, so I wasn't aware one shouldn't do this in Java. By the way, not sure if that was a tip or a solution but it didn't fix the issue. Thanks, though. Quote Link to comment Share on other sites More sharing options...
Apaec Posted May 6, 2019 Share Posted May 6, 2019 (edited) 3 hours ago, Naked said: You should never check != null with anything else. Nest them. Player player = getPlayers().closest(PLAYER_NAME); if (player != null){ if(player.interact("Trade with")) { } } Why not? I don't see anything wrong with having them on the same line. -Apa @Lansana Camara Does the player name have a space in it? The names for players may include non-breaking spaces so you may need to account for this. Edited May 6, 2019 by Apaec 2 Quote Link to comment Share on other sites More sharing options...
Sana Posted May 6, 2019 Author Share Posted May 6, 2019 (edited) 5 hours ago, FuryShark said: It works for me, have you remembered to click refresh on osbot? also try adding log() s to see where its getting to. also have you made sure the username is spelt correctly Yeah it doesn't work, I tried all that. When I log, it seems that the code stops running at the point that I log because the log never appears in that function, but it appears in logic right before the function. So strange. I'm using the following to do my logs since `log()` doesn't log to the OSBot debugger: getBot().getLogger().debug("..."); Also, If it makes any difference, the characters aren't in a "normal" area. They are at a runecrafting altar...perhaps that somehow messes with the OSBot API's and makes it so that the characters can't be seen? Edited May 6, 2019 by Lansana Camara Quote Link to comment Share on other sites More sharing options...
Sana Posted May 6, 2019 Author Share Posted May 6, 2019 44 minutes ago, Apaec said: Why not? I don't see anything wrong with having them on the same line. -Apa @Lansana Camara Does the player name have a space in it? The names for players may include non-breaking spaces so you may need to account for this. Thanks! The issue was dealing with space. Fixed by converting white spaces to nonbreaking spaces. 1 Quote Link to comment Share on other sites More sharing options...
Psychotechno Posted March 20, 2021 Share Posted March 20, 2021 On 5/6/2019 at 11:14 AM, Sana said: Thanks! The issue was dealing with space. Fixed by converting white spaces to nonbreaking spaces. May I asked how you did this? Quote Link to comment Share on other sites More sharing options...
Delision Posted March 20, 2021 Share Posted March 20, 2021 34 minutes ago, Psychotechno said: May I asked how you did this? I ran into a similar issue recently. If you have some names you want to compare to player names in-game, you need to replace any spaces in your names with non-breaking spaces like this: String friend = "slayerguy 117"; friend = friend.replace(' ', '\u00A0'); Now if you make a comparison to names pulled from api.players methods your Strings should properly match with the names returned by player.getName(). Quote Link to comment Share on other sites More sharing options...
Psychotechno Posted March 22, 2021 Share Posted March 22, 2021 On 3/20/2021 at 10:46 PM, Delision said: I ran into a similar issue recently. If you have some names you want to compare to player names in-game, you need to replace any spaces in your names with non-breaking spaces like this: String friend = "slayerguy 117"; friend = friend.replace(' ', '\u00A0'); Now if you make a comparison to names pulled from api.players methods your Strings should properly match with the names returned by player.getName(). I thank you! Quote Link to comment Share on other sites More sharing options...