VaultNetwork.netVault Network Boards
Author Topic: Trying to figure out chat in Decal [Locked]
Xnumt
Posts: 47
Registered:
Ok myabe I try a different direction.


How would I click a control button in the Decal GUI?


Something like:

button1.PerformClick();


Where button1 is within PluginCore.
Virindi-Inquisitor  4 stars
Posts: 1,538
Registered: 2001-11-18 22:25:54
Just call your handler method...?

 

-----signature-----
Virindi
---
****Virindi Plugins FAQ**** http://www.virindi.net/wiki/index.php/Virindi_Plugins_FAQ
http://www.virindi.net - Virindi Tank, Follower, Integrator, Reporter, VCS5, XPHelper, Item Tool, HUDs, etc...
Decal Core Dev - http://www.decaldev.com
Xnumt
Posts: 47
Registered:
For some reason I cannot seem to figure myself out of a paper bag.


Thank you for the help. I knew the solution was evading me easily because I am getting frustrated.


The error I am getting completely infuriates me. When I click a button in decal, the function WriteToChat works just fine, but when I call it, it does not. Maybe I should explain what I am trying to do.


This is my goal.


I am trying to do is have a function trip in Decal to send chat type in from outside Decal’s form into AC. I have a form that starts when a user clicks a Decal GUI button.


As soon as that is done, chat from AC begins to appear in this form.


What I would like to do is then allow a person to chat back into AC from this form. Therefore at some point, Decal must get the string from this form and send it to the chatbar. Now there is no issue with the string. I can get it and it will sit and wait to be displayed. I now just need to send it to the chatbox.


This is what I have tried.


The method I first tied was using a timer. This however did not work as I began to get the above error. I tried both the system timer and the forms timer and get the same result (There was a suggestion from an old thread that the form timer might be a better choice). So I asked and someone assisted me in figuring out the proper way of calling a function in my plugin from my outside form.


So I passed the calling Decal object into the form and used that to call a function. When the user clicks the Form “Chat” button, the string is saved and the function WriteToChat within the plugin is called and then the Wrapper function is called.


The error above fallowed me there.


Next I thought, “Well I can click the button and it works, so what if I try and call the button?” Well that does not work either. I get the same error.


I am out of ideas.
Virindi-Inquisitor  4 stars
Posts: 1,538
Registered: 2001-11-18 22:25:54
Oh, I bet you are having thread issues. If you have a separate thread for your windows form you need to marshal any calls from that to Decal functions. Decal functions must be called from within the AC main thread (where most of the plugin normally resides).

 

-----signature-----
Virindi
---
****Virindi Plugins FAQ**** http://www.virindi.net/wiki/index.php/Virindi_Plugins_FAQ
http://www.virindi.net - Virindi Tank, Follower, Integrator, Reporter, VCS5, XPHelper, Item Tool, HUDs, etc...
Decal Core Dev - http://www.decaldev.com
Xnumt
Posts: 47
Registered:
I figured that was what my issue was.


So I thought (foolishly) that I could use System.Timers to call it, but I guess it too is not within the main thread but I am guessing it’s the same whether my form calls it or the System.Timers call it the call comes from outside.


I am not sure of how I would marshal call from my outside forms thread. An example of how to do this could point me in the right direction.


An alternate to that is the Decal Timer. I know it is not the ideal timer to use, but since it is within the main thread it should work (albeit irregularly for tabbed folks). Much of the examples of using this timer are old and I am not sure if it works in the same way.


It seemed like an easy thing for my first plugin to use chat. I mean nearly every plugin in the game uses chat so it should not be hard.


I seemed to have found a way to make it hard. Thank you for your help.
Virindi-Inquisitor  4 stars
Posts: 1,538
Registered: 2001-11-18 22:25:54
Create a System.Windows.Forms.Timer on the AC thread that polls for updates from the other thread.

 

-----signature-----
Virindi
---
****Virindi Plugins FAQ**** http://www.virindi.net/wiki/index.php/Virindi_Plugins_FAQ
http://www.virindi.net - Virindi Tank, Follower, Integrator, Reporter, VCS5, XPHelper, Item Tool, HUDs, etc...
Decal Core Dev - http://www.decaldev.com
Xnumt
Posts: 47
Registered:
I am such an r-tard. I understood that I was likely cross threading and because of that the timer was not working. It never occurred to me that the timer itself was cross threaded because I put it in Decal.


But the function I put it in was part of the new thread.


So I have a button that starts the form. That button has the following:


Quote:

formthread = new System.Threading.Thread(formthreadstartup);

formthread.Start();



Inside formthreadstartup I had the following


Quote:

myTimer.Tick += new EventHandler(TimerEventProcessor);

myTimer.Enabled = true;

myTimer.Interval = 1000;

myTimer.Start();

myform = new Form2(this);

myform.Controls.Add(mylist);


Application.Run(myform);



Now not paying attention, I missed the fact that formthreadstartup was part of the new thread.


I moved the myTimer out of that and into the button directly and now everything functions.


I have a few finishing touches on this and then I will release it all for the masses to mock me.


Thank your all for you help in all of this. It is very much appreciated.
Virindi-Inquisitor  4 stars
Posts: 1,538
Registered: 2001-11-18 22:25:54
A note: the System.Threading.Timer class fires on a threadpool thread (separate from the thread you created the timer on). The System.Windows.Forms.Timer class fires in the thread that created it, and that thread must have a windows message loop.

 

-----signature-----
Virindi
---
****Virindi Plugins FAQ**** http://www.virindi.net/wiki/index.php/Virindi_Plugins_FAQ
http://www.virindi.net - Virindi Tank, Follower, Integrator, Reporter, VCS5, XPHelper, Item Tool, HUDs, etc...
Decal Core Dev - http://www.decaldev.com

VaultNetwork.net is an independently operated community forum and is not affiliated with, endorsed by, or technically based on IGN, GameSpy, FilePlanet, GameStats, or the former IGN/GameSpy Vault Network.
References to VaultNetwork.net mean this site/domain. VNBoards-style presentation is a visual homage only. By using this site, you agree to the forum rules.