Confusing execution of if statementSolved

In the code below the public bool variable is initialized to true.
I verified that by leaving it at the initial value of False and the timer is never initialized.

If I let it run a few cycles and then try the "stop" command the value of dotimer is changed to false but the IF statement in the "newwhere" codeblock doesn't evaluate it properly.
The player.Reply inside the IF statement verifies that the value of dotimer was changed.

Please let me know what I am missing.
Thanks!

Please use the {;} code blocks when posting code, thanks. :)
Sorry Wulf Im a noob here.  
How do I do that.
You can click the {;} button in the toolbar when posting, add your code, and then Reply.
Thanks Will do.
using Oxide.Core.Libraries.Covalence;
using Oxide.Game.Rust.Libraries;

namespace Oxide.Plugins
{
    [Info("New Where", "PEBKAC Error", "1.0")]
    [Description("Same as whereami except that Covalence / IPlayer is used")]

    public class newwhere : CovalencePlugin
    {
        public bool dotimer = true;
        private void Init()
        {
            Puts("NewWhere mod Initialized");
        }


        [Command("newwhere")]
        private void WhereCommand(IPlayer player, string command, string[] args)
        {
            if(dotimer)
            {
                Timer myTimer = timer.Every(10f, () =>
                {
                    player.Reply($"You are at {player.Position()}" + " " + dotimer);

                });
            
            }
            else
            {
                player.Reply($"Timer should be terminated " + dotimer);
            }
            
        }

        [Command("stop")]
            private void StopTimer(IPlayer player, string command, string[] args)
            {
                dotimer = false;
                player.Reply("Timer should stop "+ dotimer);
            }
    }
}
​
What is the issue? The timer not stopping?
0x,

Issue 1:  The if statement doesn't pick up the change in the bool variable dotimer
so I cant get to test terminating the timer.

Thanks!
So you do the "stop" command, then do the "newwhere" command and it doesn't put "Timer should be terminated" in chat?
Actually the "newwhere" starts the timer and the display to the player in chat. 
At this point this will continue until the plugin is unloaded.
I get the "timer should stop" from the stop command but I never see the "Timer should be terminated" message because it never makes it into the else part of the if statement.
I continue to get the player position message  with the dotimer value of false.

I'm assuming you want to stop the timer after running the stop command. If you want to do this you would have to get a reference to the timer and destroy it.

Also the reason you are not getting the "Timer should be terminated" message after running the stop command is because you are not running the "newwhere" command again, so the if statement is not performed again.

If you were to run the "newwhere" command after the "stop" command then you would get "Timer should be terminated".

0x89A

Thank you for your help!!

It finally clicked that what was being repeated was only the information that was contained within the command line that called the timer. 

As soon as I realized that the code became much simpler.

Apologies for being thick-headed, and Thanks Again!

No problem.
Locked automatically