setSceneItemEnabled and setSceneItemLocked refusing to work
HerXayah opened this issue · 2 comments
Describe the bug
It just doesnt hide the Element in the scene. The Toggle is basically doing nothing as is the Locking function
Code Sample
public static Integer getItemID(String scene) {
leagueController.getSceneItemList(scene, getSceneItemListResponse -> {
if (getSceneItemListResponse.isSuccessful()) {
getSceneItemListResponse.getSceneItems().forEach(sceneItem -> {
if (sceneItem.getSourceName().equals("LeagueInput")) {
// why. cant. i return. this. value. without. it. being. null.
// and. why. is. this. not a. returnable. integer.??????????????????????????????????
obsIndexID = sceneItem.getSceneItemIndex();
//Logger.log(Integer.toString(obsIndexID));
}
});
}
});
return obsIndexID;
}
// for context. this MUST and should have worked. why doesnt it then? idk.
public static void toggleSceneVisibility(boolean status) {
leagueController.getSceneList(getSceneListResponse -> {
if (getSceneListResponse.isSuccessful()) {
getSceneListResponse.getScenes().forEach(scene1 -> {
if (scene1.getSceneName().equals(FileHelper.obsscene.trim())) {
try {
// timeout? no clue. better than callback
//leagueController.setSceneItemLocked(scene1.getSceneName(), getItemID(scene1.getSceneName()), false, 10000);
leagueController.setSceneItemEnabled(scene1.getSceneName(), getItemID(scene1.getSceneName()), status, 10000);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
}
Expected behavior
Hide the Visibility of said Element as status is just giving a boolean (true|false) from another function into this.
// why. cant. i return. this. value. without. it. being. null.
Because that's not how Java works...
The callback is done asynchronously, so the return is done before the callback is executed so the assignment is not done yet. If you would add a log statement before the return and uncomment the current log statement you should see that they are the other way around from what you are expecting.
If you don't want to handle the async stuff, the 2.0.0 library has an option where you don't specify the callback but a timeout, using that it is possible to write the method without the fuss. It's what you seem to have found judging by the // timeout? no clue. better than callback
comment:
public static Integer getItemID(String scene) {
GetSceneItemListResponse getSceneItemListResponse = leagueController.getSceneItemList(scene, 10_000);
if (getSceneItemListResponse.isSuccessful()) {
return getSceneItemListResponse.getSceneItems()
.stream()
.filter(sceneItem -> sceneItem.getSourceName().equals("LeagueInput"))
.findFirst()
.map(SceneItem::getSceneItemId)
.orElse(null);
}
return null;
}
The toggleSceneVisibility
doesn't need to return anything, but blocking calls within a callback currently blocks everything, so that one could then also become an in-sync method:
public static void toggleSceneVisibility(boolean status) {
GetSceneListResponse getSceneListResponse = leagueController.getSceneList(10_000);
if (getSceneListResponse.isSuccessful()) {
getSceneListResponse.getScenes().forEach(scene1 -> {
if (scene1.getSceneName().equals(FileHelper.obsscene.trim())) {
try {
leagueController.setSceneItemEnabled(scene1.getSceneName(), getItemID(scene1.getSceneName()), status, 10000);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
I'm getting a No scene items were found in scene '[name]' with the ID '1'.
response (in the console), so the commands seem to execute fine with these changes.
Edit: The getSceneItemIndex
in getItemID
was wrong, it should return the id, not index. Code snippet was changed.
Applying that change does toggle the enabled state for me.
// why. cant. i return. this. value. without. it. being. null.
Because that's not how Java works... The callback is done asynchronously, so the return is done before the callback is executed so the assignment is not done yet. If you would add a log statement before the return and uncomment the current log statement you should see that they are the other way around from what you are expecting.If you don't want to handle the async stuff, the 2.0.0 library has an option where you don't specify the callback but a timeout, using that it is possible to write the method without the fuss. It's what you seem to have found judging by the
// timeout? no clue. better than callback
comment:public static Integer getItemID(String scene) { GetSceneItemListResponse getSceneItemListResponse = leagueController.getSceneItemList(scene, 10_000); if (getSceneItemListResponse.isSuccessful()) { return getSceneItemListResponse.getSceneItems() .stream() .filter(sceneItem -> sceneItem.getSourceName().equals("LeagueInput")) .findFirst() .map(SceneItem::getSceneItemId) .orElse(null); } return null; }The
toggleSceneVisibility
doesn't need to return anything, but blocking calls within a callback currently blocks everything, so that one could then also become an in-sync method:public static void toggleSceneVisibility(boolean status) { GetSceneListResponse getSceneListResponse = leagueController.getSceneList(10_000); if (getSceneListResponse.isSuccessful()) { getSceneListResponse.getScenes().forEach(scene1 -> { if (scene1.getSceneName().equals(FileHelper.obsscene.trim())) { try { leagueController.setSceneItemEnabled(scene1.getSceneName(), getItemID(scene1.getSceneName()), status, 10000); } catch (Exception e) { e.printStackTrace(); } } }); } }I'm getting a
No scene items were found in scene '[name]' with the ID '1'.
response (in the console), so the commands seem to execute fine with these changes.Edit: The
getSceneItemIndex
ingetItemID
was wrong, it should return the id, not index. Code snippet was changed. Applying that change does toggle the enabled state for me.
Hey!
Many thanks for your response.
Apreciate it and will try 👍