• Visit Rebornbuddy
  • CraftingManager.CurrentRecipeId returning 0 from a form

    Discussion in 'Community Developer Forum' started by Rawrskies, Oct 15, 2015.

    1. Rawrskies

      Rawrskies New Member

      Joined:
      Aug 8, 2015
      Messages:
      14
      Likes Received:
      2
      Trophy Points:
      3
      Hi all,

      I'm trying to get the current recipe ID when I click a button on the settings form of a botbase. However when I do this it always returns 0. If I try to run the exact same thing through the console, it'll return the correct ID; but it's always 0 when I push the button on the form/settings window. Am I missing something here?

      Code:
      private void btnCheck_Click(object sender, EventArgs e)
              {
                  Logging.Write(CraftingManager.CurrentRecipeId);
              }
      Result : 0
       
    2. Wheredidigo

      Wheredidigo Community Developer

      Joined:
      Dec 15, 2013
      Messages:
      417
      Likes Received:
      8
      Trophy Points:
      18
      Yes, the form is on the UI thread and doesn't have the correct context for getting the right value. You can actually take a look through the Console's code to see how it's doing it. I ran down this road quite awhile ago and ended up giving up on it myself because it was just beyond my realm of expertise.
       
    3. Rawrskies

      Rawrskies New Member

      Joined:
      Aug 8, 2015
      Messages:
      14
      Likes Received:
      2
      Trophy Points:
      3
      The console's not entirely helpful as it's compiling the code and then running it. But I'll see if I can find out how to do what I'm after :S I'll let you know how I was able to do it when I've got it working. Until then, if someone else would like to chime in and provide an answer; that wouldn't go entirely unwanted! :)
       
    4. mastahg

      mastahg Administrator Staff Member

      Joined:
      Feb 27, 2011
      Messages:
      5,232
      Likes Received:
      364
      Trophy Points:
      83
      First working in another thread can sometimes be a bad idea but if your using it only to display information you sometimes get away with it. Basicly we use a memory cache for reads and these caches are perthread so you have to handle clearing the cache your self if your operating in a thread outside the main one. Look at the quest profile plugin and see how it wraps any api calls in a using like this

      Code:
                  using (Core.Memory.TemporaryCacheState(false))
                  {
                  }
      
      
      Also, since most of the *Managers use a threadlocal cache the questdev plugin also pulses GameObjectManager.Update(); but if your not messing with gameobjects you won't need todo that really.
       
    5. Rawrskies

      Rawrskies New Member

      Joined:
      Aug 8, 2015
      Messages:
      14
      Likes Received:
      2
      Trophy Points:
      3
      Thanks a bunch. I'll give that a shot when I get home. But as you suspected, I'm only using it to display information. Figured it'd be easier to get the information from the game rather than storing it externally, so I won't need to worry about keeping an external copy up to date.
       

    Share This Page