1. Hi, i cant find this information:

    in Oxide, C# plugin, is it possible to pass input parameters to timers? If so, how can i pass parameters?

    I want multiple independent timers and make sure they will execute the same function but using different input variables.

    I really cant figure it out. I can't find any documentation for Oxide.Core.Libraries.Timer.TimerInstance

    Code:
    private void DelayedUiCloseDo(Something s){
        // here i need input variables
        s.testUI.Destroy(s.crafter);
    }
    private void DelayedUiClose(UIObject testUI, BasePlayer crafter)
    {
        // can i send somehow input variables from here to timer?
        var timerInstance = new Oxide.Core.Libraries.Timer.TimerInstance(1000, 1000, DelayedUiCloseDo, this);
    }private void OnItemCraft(ItemCraftTask task, BasePlayer crafter)
    {
        UIObject testUI= new UIObject();          
        UIColor color = new UIColor(0.5, 0.5, 0.5, 0.5);
        testUI.AddPanel("myUIpanel", 0, 0, 0.1, 0.1, color, false, "HUD/Overlay");
       
        testUI.Draw(crafter);   
       
        // input variables came from here originally
        DelayedUiClose( testUI,  crafter);
    }
     
  2. Wulf

    Wulf Community Admin

    Everything you should need to know about timers is shown in the Docs link at the top of the page.
     
  3. Thx a lot, google gives 10 results.

    And search in Docs link at the top of the page gives me:
    • No Results Found for "timer"
    Then after more search in docs i could find Rust which is basically nothing = as little info as can be given :( with no info about passing variables...

    This thread is one of 10 google links to this topic.
    Could you please respond here clearly, is there any way to pass input variables to function called by timer(s)?

    If there is no way to pass variables just say no pls. If there is way to do it, simple example would be greatly appreciated.

    Thx for your time Wulf :)
     
  4. Wulf

    Wulf Community Admin

    I linked it directly in my previous reply, just click on the "Docs" part.
     
  5. Yes it is the same what i linked, but how to do it, pls.

    Is this correct?

    Code:
    str="Hello World!";timer.Once(3f, (str) =>
    {
        Puts(str);
    });
    

    But how do i make it function, how to take that part of code out to not be inline?

    This is all-WRONG syntax of what i would like to do:

    Code:
    sayText = function(str)
    {
       Puts(str);
    }str="Hello World!";timer.Once(3f, sayText(str) );
    
    Please how to use a function and pass input variables in timer.Once(3f, _here_ ); ?
     
  6. Wulf

    Wulf Community Admin

    Code:
    timer.Once(3f, () => sayText(str));
    That's one example, but there are other ways of doing it as well.
     
  7. Ye but that i was already trying like this:
    Code:
    private void DelayedUiCloseDo(UIObject testUI, BasePlayer crafter){
                testUI.Destroy(crafter);
            }
            private void DelayedUiClose(UIObject testUI, BasePlayer crafter)
            {
                var timerInstance = new Oxide.Core.Libraries.Timer.TimerInstance(1000, 1000, DelayedUiCloseDo(testUI, crafter), this);           
            }
    Which leads to error:

    [Oxide] 07:46 [Error] myTest plugin failed to compile!
    [Oxide] 07:46 [Error] myTest.cs(241,81): error CS1503: Argument `#3' cannot convert `void' expression to type `System.Action'
    [DOUBLEPOST=1461217852][/DOUBLEPOST]So this compiles:
    Code:
    private void DelayedUiCloseDo(UIObject testUI, BasePlayer crafter){
                testUI.Destroy(crafter);
            }
            private void DelayedUiClose(UIObject testUI, BasePlayer crafter)
            {
                var timerInstance = new Oxide.Core.Libraries.Timer.TimerInstance(1000, 1000, () => DelayedUiCloseDo(testUI, crafter), this);           
            }
    () => DelayedUiCloseDo(testUI, crafter)

    instead of

    DelayedUiCloseDo(testUI, crafter)
    [DOUBLEPOST=1461218821][/DOUBLEPOST]But it actually does not work:

    Code:
    private void DelayedUiCloseDo(UIObject testUI, BasePlayer crafter){
        Log("DelayedUiCloseDo run...");
        testUI.Destroy(crafter);
    }
    private void DelayedUiClose(UIObject testUI, BasePlayer crafter)
    {           
        Log("DelayedUiClose run...");
        var timerInstance = new Oxide.Core.Libraries.Timer.TimerInstance(1000, 1000, () => DelayedUiCloseDo(testUI, crafter), this);   
    }
    
    "DelayedUiClose run..." is in logs but "DelayedUiCloseDo run..." never appears
    [DOUBLEPOST=1461219746][/DOUBLEPOST]Finally, this is working fine:
    Code:
    private void OnItemCraft(ItemCraftTask task, BasePlayer crafter)
    {
        Puts("OnItemCraft hook");
           
        UIObject testUI= new UIObject();           
        UIColor color = new UIColor(0.5, 0.5, 0.5, 0.5);
       
        testUI.AddPanel("myUIpanel", 0, 0, 0.1, 0.1, color, false, "HUD/Overlay");
        testUI.Draw(crafter);
       
        timer.Once(5, () =>
        {
            testUI.Destroy(crafter);
        });   
    }
    testUI and crafter variables are passed to the timer function...
     
  8. Wulf

    Wulf Community Admin

    That would run after 5 seconds. It looks fine, so perhaps the issue is with your methods being called?
     
  9. The last part is working fine..
     
  10. Wulf

    Wulf Community Admin

    Okay, so what is the issue? The last part is the correct way to call it, the first part isn't.
     
  11. Issue was "How to pass variables to a timer" and solution is:
    Code:
    private void OnItemCraft(ItemCraftTask task, BasePlayer crafter)
    {
        Puts("OnItemCraft hook");
       
        UIObject testUI= new UIObject();        
        UIColor color = new UIColor(0.5, 0.5, 0.5, 0.5);    testUI.AddPanel("myUIpanel", 0, 0, 0.1, 0.1, color, false, "HUD/Overlay");
        testUI.Draw(crafter);    timer.Once(5, () =>
        {
            testUI.Destroy(crafter);
        });
    }
    Thank you for all the help
     
  12. Wulf

    Wulf Community Admin

    No problem, just wanted to make sure, as it sounded like you were still questioning it.
     
  13. This has nothing to do with oxide.
    Look up what first class functions, callbacks and closures are.
     
  14. Thank you for your care, really appreciated, your comment helps so much.
     
  15. It would also help if you are a bit more friendly to people who are trying to help you.
     
  16. wtf r u talking about mate... sqroot was not trying to help me.. i was frienly to mr Wulf who helped a lot

    thx Wulf again :)
     
  17. Sure I was. You were asking things related to the language you are using, not to Oxide.
    I named the concepts you need to understand to able to properly do what you wanted to do.
    Just copying solutions and not understanding the language features that lead to the result will eventually result in you hitting another barrier the next time you have a slightly different but similar problem.