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
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.
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!
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.
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.