Resolved Resources cannot be loaded from the bot constructor

Discussion in 'Developer Support' started by Aidden, Feb 14, 2016.

  1. So special thanks to @Savior for working out why my resource loading wasn't working.

    @Cloud @Arbiter The reason it wasn't working was because i was creating my gui in the bot constructor, as you said to do @Arbiter (you moved the line in there when you tv'd me). As soon as i moved it to onStart it loaded the fxml perfectly fine.

  2. Best Answer:
    Post #6 by Arbiter, Feb 17, 2016
  3. The reason for this is the getScript() method returns null if the code/thread is still in the constructor of the bot.
    Qosmiof2 likes this.
  4. @Arbiter - thoughts on whether to consider this an actual bug?
  5. It's definitely a problem, because now we have conflicting requirements: we are requiring developers to set the EmbeddableUI in the no-args constructor, but we aren't letting them initialize the UI there. :/
  6. Is there a reason why there can't be a default EmbeddableUI, where we just pass the node and shit gets done? Like, bot.setUi(coolUiParent);?
  7. Solution: Stop trying to load resources in the constructor. Lazily instantiate (and thus load resources for) UI upon invocation of the botInterfaceProperty() method in EmbeddableUI. How many times do I need to mention this?

    Code (Java):
    2. public class DevelopmentToolkit extends LoopingScript implements EmbeddableUI {
    4.     public DevelopmentToolkit() {
    5.         setEmbeddableUI(this);
    6.     }
    8.     ...
    10.     @Override
    11.     public ObjectProperty<DevelopmentToolkitPage> botInterfaceProperty() {
    12.         if (botInterfaceProperty == null) {
    13.             try {
    14.                 developmentToolkitPage = new DevelopmentToolkitPage();
    15.             } catch (IOException ioe) {
    16.                 System.err.println("Failed to load Development Toolkit UI.");
    17.                 ioe.printStackTrace();
    18.             }
    19.             botInterfaceProperty = new SimpleObjectProperty<>(developmentToolkitPage);
    20.         }
    21.         return botInterfaceProperty;
    22.     }
    24.     private ObjectProperty<DevelopmentToolkitPage> botInterfaceProperty;
    26. }
    --- Double Post Merged, Feb 17, 2016, Original Post Date: Feb 17, 2016 ---
    --- Double Post Merged, Feb 17, 2016 ---
    I support this idea, but it would have to be Callable<Node> and would still need to be in the no-args constructor. Would be relatively easy to implement on our end. Please create a feature request.
  8. The issue is when things rely on stuff like metadata, which can't be called until onStart, which includes getSettings(), which I use for saving profiles, because that calls getMetaData().isLocal(), and it seems like the UI is being set before onStart(), but after initialisation.
    This can be remedied by lazyloading the UI, and adding things that rely on metadata in onStart, but that's only if you're guaranteed that it'll be called before onStart. Another thing that could be done, is making the metadata available before setting the UI.

    Is the flash you're talking about due to the image disappearing/being pushed down when the UI is loaded during onStart? At the moment I add panes dynamically, which pushes down the image anyway. I was thinking about making the UI fit the space, having static top bar, and putting the panes in a ScrollPane so when they're expanded you can still scroll though them, which would make sure that the image is always absent when there is a UI, and that the runtime and status are always viewable, which @Savior has already suggested

    Or if the flash is the where the "This bot has no UI" message disappears, then if you set the property to something empty like a new VBox or Text then that message doesn't appear xD

    Either way, I've separated the parts of my UI that require metadata and adding them in onStart, and loading the rest of the UI w/ lazyloading.

    TLDR: Make metadata available before loading the UI pls, and mayyybe allow the bot interface to take the dimensions of the bot ui area.
    #7 SlashnHax, Feb 18, 2016
    Last edited: Feb 18, 2016
  9. Again, you should have full access to the metadata if you're lazy loading the UI. I'm going to leave it at that unless you confirm otherwise.
  10. Yeah you're right xD The issue was I was using a metadata variable that I set in onStart haha.
    Still, it's a pain when you want to have things loaded into the UI that aren't specifically part of the UI, a BreakHandler with profiles kept in the ManagedProperties. I've decided to create those things and their respective panes in onStart, which doesn't seem to be an issue.

Share This Page