Modding Help Rpc Promise not working for GUI

Discussion in 'Starbound Modding' started by jakecool19, Mar 2, 2019.

  1. jakecool19

    jakecool19 Pangalactic Porcupine

    For whatever reason I can't seem to get an Rpc promise back from using the world.sendEntityMessage from the gui to the object. Checking finished is says that its false, succeeded is false and results and error return nothing although I know the message is being sent and the object the pane is connected to will run whatever function is tied to the handler. World.callScriptedEntity will not work and I can't try to send a message back to the pane because it isn't an entity. Any help appreciated! P.S. The message in question is the "gsample" one.

    Code:
    function init()
      storage.timer = 0
      message.setHandler("sample", sample)
      message.setHandler("gsample", function()
      return storage.sample
      end)
      getRecipe()
    end
    



    Code:
    function init()
    check = false
    end
    
    function update(dt)
      if check == false then
        local promise = world.sendEntityMessage(pane.containerEntityId(), "gsample")
        if promise:finished() then
          if promise:succeeded() then
            widget.setText("outputText", "^#b9b5b2;Recipe set: "..promise:result())
            check = true
          end
          promise = nil
        end
      end
    end
    
    function sample()
        world.sendEntityMessage(pane.containerEntityId(), "sample")
        local sample = world.containerItemAt(pane.containerEntityId(),0);
        if sample ~= nil then
          widget.setText("outputText", "^#b9b5b2;Recipe set: "..sample.name)
          else
          widget.setText("outputText", "^#b9b5b2;Put a item in the top slot, and click the button to set a recipe.") end
    end
     
  2. Errors4l

    Errors4l Spaceman Spiff

    How can the message succeed if it hasn't finished running the code yet? Objects are server sided and your GUI is client sided.

    Even on single player, this means that your message will send a request to the 'server' to run the message handler. The results are returned whenever the server has some spare time to run the code and return the result.

    You may use the PromiseKeeper class provided in the game assets to 'wait' for this response by the server, and handle the result or possible errors.
    Here's more info: https://github.com/Silverfeelin/Starbound-MessageHandling-Demo/wiki/Promise-Keeper
     
    jakecool19 likes this.

Share This Page