Dstudent
Newbie
Posts: 8
Joined: Mon Mar 21, 2016 3:38 pm

Eventhandler variables

Wed May 04, 2016 12:50 pm

I've been playing with Syn.Bot in C# for a while now and everything seems pretty straight-forward. I noticed I could have an eventhandler for userSettings, and this seemed like a fun thing to use.

CSharp Code

user.Settings.SettingsChanged += Settings_SettingsChanged;
private void Settings_SettingsChanged(object sender, Syn.Bot.Events.SettingsChangedEventArgs e)
{
       //code here
}
The tooltip reads:
Occurs when a Variable is added, removed or updated.
But the Event doesn't trigger on updated. Only on added (I haven't tested removed). I had expected this to work much like the user.EmotionChanged eventHandler, which does trigger on updated. Has this not been implemented yet?

User avatar
Fantom
Help & Support
Posts: 304
Joined: Fri Oct 25, 2013 9:20 pm

Re: Eventhandler variables

Wed May 04, 2016 7:28 pm

The SettingsChangedAction has 4 values that is Add, Remove, Replace and Reset so if a variable's value is changed it won't trigger the SettingsChanged event. However, to check if a particular variable is updated you can use the Changed event on that variable.

CSharp Code

User.Settings["MyVariable"].Changed

Dstudent
Newbie
Posts: 8
Joined: Mon Mar 21, 2016 3:38 pm

Re: Eventhandler variables

Wed May 04, 2016 7:57 pm

I can simply iterate over variables and set listeners that way. :D
That works! Thank you ;)

It's surprising how well-setup the software is. SIML script is really easy to set up and can accomodate quite complex features :) Kudos for the developers!

Dstudent
Newbie
Posts: 8
Joined: Mon Mar 21, 2016 3:38 pm

Re: Eventhandler variables

Mon May 09, 2016 1:27 pm

Oh, I have one more question. Since the sender is the variable object, there's no way to link a specific user to the variables that have changed, is there?

User avatar
Fantom
Help & Support
Posts: 304
Joined: Fri Oct 25, 2013 9:20 pm

Re: Eventhandler variables

Tue May 10, 2016 5:27 pm

Sorry I didn't get your question. Every user has a separate Settings property so if you handle a variable changed event then you are already handling the variable changes for that particular user. This is one of the reason the Sender is not the user.

Dstudent
Newbie
Posts: 8
Joined: Mon Mar 21, 2016 3:38 pm

Re: Eventhandler variables

Fri May 13, 2016 1:10 pm

I realized this and managed to solve the problem :)
For me it was as simple as finding out that the event was called before the created response was sent in my application.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests