Results 1 to 6 of 6

Thread: working with exec_async

  1. #1
    ... connecting
    Join Date
    May 2019
    Posts
    8
    Thanks
    7
    Thanked 4 Times in 4 Posts

    working with exec_async

    I have a couple questions about the async methods.
    I tried to implement them as best as I could, an example
    PHP Code:
    dosomething_async(killer killd)
    {
        
    exec_async_create("./save.sh " killer " " +  killd, ::dosomething_result_async);
        
    check_async();
    }

    dosomething_result_async(result)
    {
        
    level notify("stop_async");
        
    entity GetEntByNumint(result[0]));
        if(
    result[1]=="OK"){
            
    entity iprintln("OK");
        }
        else{
            
    entity iprintln("ERROR"result[1]);
        }
        
    }

    check_async()
    {
        
    level endon("stop_async");
        for(;;)
        {
            
    wait 0.05;
            
    exec_async_checkdone();
        }    
    }

    killed(eInflictoreAttacker)
    {
        
    killer eAttacker GetEntityNumber();
        
    killd self GetEntityNumber();

        if(
    killd!=killer)
        {
            
    dosomething_async(killer killd);
        }

    i get error
    PHP Code:
    ******* script compile error *******
    return 
    value of developer command can not be accessed if not in a /# ... #/ comment: (file 'maps/mp/gametypes/_kill.gsc', line 10)
     
    entity GetEntByNum(int(result[0])); 
    do you have any ideas?

    My goal is to iprintln on client only after correctly using save.sh

    Second question if two events are launched (kill events in this case) and then the first one terminates and notifies "stop_async" do both check_async terminates? or only the first one?

  2. The Following User Says Thank You to Miri For This Useful Post:

    kung foo man (29th May 2019)

  3. #2
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    PHP Code:
    dosomething_result_async(result)
    {
        
    //level notify("stop_async");
        
    entity clientNumToEntityint(result[0]));
        if(
    result[1]=="OK"){
            
    entity iprintln("OK");
        }
        else{
            
    entity iprintln("ERROR"result[1]);
        }
        
    }

    clientNumToEntity(num)
    {
        
    players getentarray("player""classname");

        for (
    0players.sizei++)
        {
            if (
    players[igetEntityNumber() == num)
                return 
    players[i];
        }

        return 
    undefined;

    You should call check_async() on gametype start, not on some event, it should always be running.
    Notify stops all running threads with the corresponding endon.
    And you REALLY should't use exec to to that kind of stuff, mysql/sqlite should be used for that and they can also be called directly on entities.
    Last edited by voron00; 28th May 2019 at 21:01.
    sudo apt-get rekt

  4. The Following 2 Users Say Thank You to voron00 For This Useful Post:

    kung foo man (29th May 2019),Miri (29th May 2019)

  5. #3
    ... connecting
    Join Date
    May 2019
    Posts
    8
    Thanks
    7
    Thanked 4 Times in 4 Posts
    why GetEntByNum() doesn't work? it's even in the documentation! anyway your code works great, thanks!

    Quote Originally Posted by voron00 View Post
    You should call check_async() on gametype start, not on some event, it should always be running.
    can that infinite check cause performance problems? Dunno just asking.

    Quote Originally Posted by voron00 View Post
    Notify stops all running threads with the corresponding endon.
    Yeah you're right I setup a test to try and it stops all with the same name. That's why I have now a dynamic name for the event so it stops the right one everytime.
    But if you're telling me that I can just leave it running forever without performance problems, it's easier to do.

    Quote Originally Posted by voron00 View Post
    And you REALLY should't use exec to to that kind of stuff, mysql/sqlite should be used for that and they can also be called directly on entities.
    I actually send the data with curl to another server don't need to store anything here. SQL server is not exposed on the internet.
    I was using python before to send the data but I think with .sh is faster.
    Is this such a shitty architecture? I'd love suggestions on all fronts, as always thank you for the heads up.
    Last edited by Miri; 29th May 2019 at 06:03.

  6. The Following User Says Thank You to Miri For This Useful Post:

    kung foo man (29th May 2019)

  7. #4
    Corporal voron00's Avatar
    Join Date
    Nov 2014
    Posts
    248
    Thanks
    64
    Thanked 216 Times in 116 Posts
    GetEntByNum() is one of those functions with a developer flag, they only work in a /# ... #/ comments like:

    PHP Code:
    /
        
    entity clientNumToEntityint(result[0]));
        if(
    result[1]=="OK"){
            
    entity iprintln("OK");
    #/ 
    Compiler will ignore everything under /# ... #/ comments unless developer_script is set to 1.

    There is no performance impact on calling exec_async_checkdone every frame, well you can call it
    not per frame maybe every 0.1 or something but you're gonna end up with slightly delayed callbacks then.
    Last edited by voron00; 29th May 2019 at 07:20.
    sudo apt-get rekt

  8. The Following 2 Users Say Thank You to voron00 For This Useful Post:

    kung foo man (29th May 2019),Miri (29th May 2019)

  9. #5
    Sergeant maxdamage99's Avatar
    Join Date
    Aug 2014
    Location
    Russia
    Posts
    458
    Thanks
    79
    Thanked 122 Times in 101 Posts
    maybe I misunderstood you, but ..

    PHP Code:
    execute_aCD()
    {
        
    exec_async_checkdone();
    }

    aExecute_getID()
    {
        
    id level.sv_dataVar["tech"]["exec_count"];
        
    level.sv_dataVar["tech"]["exec_count"]++;
        
        return 
    id;
    }

    aExecute_callback(resultid)
    {
        
    level.exec_buffer[id] = result;
        
    level notify("aExecute_" id);
    }

    aExecute(query)
    {
        
    printf("%\n"query);

        
    id aExecute_getID();
        
    exec_async_create(query, ::aExecute_callbackid);
        
        
    level waittill("aExecute_" id);
        
    result level.exec_buffer[id];
        
        return 
    result;
    }

    aExecute_(query)
    {
        
    printf("%\n"query);
        
    exec_async_create_nosave(query);

    server init:
    PHP Code:
    level.sv_dataVar["tech"]["exec_count"] = 0;
    level.exec_buffer = []; 
    call:
    PHP Code:
    result aExecute("php somework.php " arg1 " " arg2);
    if (!
    isDefined(result))
    {
        
    //execution error
    }

    if (
    result[0] == "ERROR")
    {
        
    //script executed but returned error

    this is for "undefined" if for some reason the script was not executed:
    https://github.com/damage99/libcod/b..._exec.cpp#L104


    it helped me with problem:
    the script was not executed (lack of RAM in my cases)

    all other errors (invalid arguments, wrong args types, etc.) can be processed already in the script itself (.sh, .php etc.)
    Last edited by maxdamage99; 1st June 2019 at 22:23.
    PHP Code:
    class CoronaVirus 
    {
       
    CoronaVirus(int m 1): multi(m) { Peoples.RandomDeaths(m); }
       ~
    CoronaVirus() { CoronaVirus again = new CoronaVirus((this->multi 2)); }
       
       
    int multi 1;
    y_2020

  10. The Following User Says Thank You to maxdamage99 For This Useful Post:

    Miri (2nd June 2019)

  11. #6
    ... connecting
    Join Date
    May 2019
    Posts
    8
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Nice, simple and clean code! Mine is very much spaghetti but it does the job. I'll use this for future implementations.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •