You can just set a boolean flag when you enter the house.
For example:
public class YourScript extends Script {
private boolean hasEnteredHouse;
@Override
public int onLoop() throws InterruptedException {
if (!inHouse()) {
// If we're not in the house, enter it
enterHouse();
} else {
// We are inside the house, so we can set hasEnteredHosue to true
// so that next time we enter the house, we can use the last visit functionality
hasEnteredHouse = true;
}
return 600;
}
public boolean enterHouse() {
if (hasEnteredHouse) {
// We have entered the house before, use the last visit functionality
} else {
// We have not entered the house before, use the search
}
}
}
Or alternatively, set a different flag when you see the "You haven't visited anyone this session." message.
For example:
public class YourScript extends Script {
private boolean visitedPlayerHouse = true;
@Override
public int onLoop() throws InterruptedException {
if (!inHouse()) {
// If we're not in the house, enter it
enterHouse();
} else {
// We have entered the house, so we set visitedPlayerHouse to true
// so that next time we go to enter a house, we know that we can use the
// last visit functionality
visitedPlayerHouse = true;
}
return 600;
}
public boolean enterHouse() {
if (visitedPlayerHouse) {
// We have entered the house before, use the last visit functionality
} else {
// We have not entered the house before, use the search
}
}
@Override
public void onMessage(Message message) {
if (message.getType() != MessageType.GAME) {
return;
}
// When we see this GAME message
if (message.getMessage().contains("You haven't visited anyone this session.")) {
// We set visitedPlayerHouse to false
// So that we know to use the search functionality to enter the house next time
visitedPlayerHouse = false;
}
}
}
Note I have not tested any of the above code, but it should give you an idea how to do it.