How to disable a function from user input (button)

Quick question,

I currently have a project that notifies me via twilio if a door is open of closed. On my app I’ve implemented a functionality so that the user can either enable or disable sms. The posting/requesting are working just fine. I’m just trying to find the best way to disable the sendsms() function when the user clicks the button and then be able to re enable it when the enable button is selected.

I tried to set a variable (flag) so that when the disable button is clicked it jumps to a disablesms function where I assign this flag =1. Then in the sendsms function do a simple if(flag ==0) it will check to verify if it’s a zero that is when flag ==0 we know it’s the enable flag and procede to send sms. If the disabled button is selected, flag gets assigned to 1 and if smsflag ==1 then the sms function won’t follow through.

I hope this makes sense. And apologize if it does not. Just wanted to get some feedback.

Thanks as always.

Is this part of your agent code, or an app? If the latter, you should be able to check the state of the switch when it’s moved, and proceed to enable or disable SMS accordingly. It’s always best, I’ve found to check switch states directly rather than rely on flag set or unset the previous time the switch was moved.

The app side just sends the button request. The agent Side gets the request then jumps to the enable or disable function accordingly.

The way you tackle this depends on how many people can have the app open at the same time. For example, if two people have app open and one one person clicks button to disable SMS, is the disable option just for that person’s device / username or is it then meant to disable SMS for all persons. Derived solution depends on answer given.

It’s not as complicated as specific people it’s just a simple overall approach. That is, it would disable sms and not send messages to my phone. I only myself hard coded into sending messages so that’s where I’m leaving it for now. The flag thing isn’t working, the sms function still goes through regardless of the if statement

Sounds like you’re using the right approach but have a bug in your code somewhere. Any chance you’d be willing to share it (make sure you take out any private info like phone #s and API keys first).

Scratch that, I resolved the bug. It’s always something so small. Thanks as always for the quick replies and insight!