• 0

    posted a message on Scripting functions that run based on conditions

    With regards to TriggerDestroy(t), I suppose its good practice to destroy all trigger variables after they are used? Or is galaxy smart enough to help us collect and dump garbage. I know this is a little off topic here but i'm wondering if there are any variable types that can potentially leak. In JASS it was points and units i believe, always had to null them after usage.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Scripting functions that run based on conditions

    I kinda learned the same way you are learning now. Looking at examples and pulling them apart like a puzzle. Reverse engineering is the way to go :P You'll tend to learn some nifty tricks here and there simply from looking at codes other than your own.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Scripting functions that run based on conditions

    No probs mate. Yeap, void means no return type, thus we "return;" if we want to skip remaining actions. "return true;" would instead be used if the function was a bool type.

    I don't think it's entirely correct to say that the entire code is run only once from top to bottom. When we finish programming our functions we "Compile" them. Once compiled you could say the functions are stored into the PC's memory whenever we load the map to be called later. Here's how I understand it... If I'm wrong I do encourage someone to come along and correct me.

    <Memory>
    Function A - When I type "-test"
    Function B - Every 1 seconds
    Function C - Unit is Selected
    </Memory>
    

    Whenever an event fires and triggers a function, only that function will run once from top to bottom. If I type -test, a thread will be created for Function A, once it finishes its run, it will return to main() (though im not too sure what main() is in galaxy >_>) When a function is called, it will always execute/check only what is within its curly braces { } Function B will create a thread every 1 second and check conditions inside it.

    So every time a function is run/called, it will recheck the conditions inside it.

    To have a code that is called once but continuously checks for conditions to run actions, I would do this:

    void code(){
    while(true){ //Loops forever
    if( conditions met){
        //Run actions
    }
    Wait 1 second; //This is essential or your function will crash with the error saying it took too long to execute.
    }
    }
    

    Whenever you use a wait, any other function that is queued in the processor will have a chance to run.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Scripting functions that run based on conditions
    Quote from Vermore: Go

    does programs run through the compiled code every 0.01 seconds?

    A function is only executed if it is called. It doesn't run every 0.01 seconds, unless you have a periodic event that calls your function. Yes, you are right on this one, it will be quite wasteful on CPU usage. When a function is called, the lines in it are run in sequence, top to bottom.

    To have a function that only runs its contents if it is true, I believe it's as simple as using a return statement.

    void function(){
    if (conditions not met){
        return;
    }
    
    //actions
    }
    

    When a function is called, a "thread" is created. The return statement tells a function to terminate a "thread" and return to its caller. In the example above, if he conditions are not met, the function will return and ignore the actions. Forgive me for any confusion.. i really suck at understanding questions and explaining stuffl. ><

    Posted in: Galaxy Scripting
  • 0

    posted a message on Scripting functions that run based on conditions

    Ah okay. I believe the bare minimum is

    bool action(bool testConds, bool runActions){
    //your script
    return true;
    }
    
    void init(){
    //insert trigger/event initializations
    }
    

    Unless theres a way to attach events directly to a non-trigger function, I don't think its possible. AFAIK, an event must be attached to a trigger. =/

    Posted in: Galaxy Scripting
  • 0

    posted a message on Scripting functions that run based on conditions

    If i'm understanding your question right, the syntax is something like this,

    void customfunction(){ 
    //your custom script
    }
    
    bool action(bool testConds, bool runActions){
    
    if(testConds){
    //Your conditions here whether or not it is unit X
        if(EventUnit() != *your unit X here*){
        return true;
        }
    }
    
    if(runActions){
    //Your actions/function calls here
    customfunction();
    }
    
    return true;
    }
    
    void init(){
    trigger t = TriggerCreate("action");
    
    //Attach events to triggers with trigger add event functions.
    TriggerAddEvent... //The unit entered region event
    
    }
    

    From what i understand the booleans testconds is used in cases where you want to do "Run Trigger Checking Conditions, Ignore Conditions". Same case with runActions, as you may just want to evaluate the conditions. The if loops that check them are not necessary if you will never do such checks.

    If you want your custom script to run on game init just fill in the name of the initialization function at the bottom of the custom script block. In my case is init(). so I will put init

    Hope I answered your questipn =/ You can press Ctrl + F11 to see galaxy script of your GUI triggers as well to see how they are compiled by the galaxy editor.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Stumped by Recursion problem =(

    Thanks for the feedback guys.

    s3rius' psuedocode about sums it up.

    Yes, I am indeed using the UnitHighlight event, I can't seem to find any other viable alternatives at this point. I just tried a wait of 0.0. It still doesn't scale up quick enough, and for some annoying reason, its not recording the results properly (Will attach screenshot of this when I'm able)

    Heres my code.. sorry if it's messy I didn't want to break it into pseudocode as It might not be very clear how it's supposed to operate. If you guys are wondering, I'm trying very hard to develop an asset to track the position of the mouse cursor through GPS triangulation. I've tried about 10 other methods already, some are responsive but not accurate. Some are accurate but not responsive enough. :(

    //This is a 0.05 periodic event, thus the requirement for a Lock [b_isPingGPS]
    //My global arrays are as follows
    //f_radiusGPS = The scale of the units/pings
    //b_pingGPS = Hit Flags for each of the pings
    //u_pingGPS = Stores the ping units
    //f_scaleGPS = 90.0; //Scaling constant
    
    bool hitGPS(){
        //Variable Initialization
        unit u = EventUnit();
        int i = 0;
    
        //Actions: Switch True/False states
        while(i < 2){
            if( u == u_pingGPS[i] && !b_pingGPS[i]){
                b_pingGPS[i] = true;
                f_radiusGPS[ModI(i+1,2)] = 80.0-f_radiusGPS[i]-1.0;  //A scale of 80 is required to traverse the width of my widescreen.
                UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringExternal("Hit" + IntToString(i) + " T/F: " +         libNtve_gf_ConvertBooleanToString(b_pingGPS[i]) + " Rad: " + FixedToString(f_radiusGPS[i],2))); 
                libNtve_gf_ShowHideUnit(u_pingGPS[i], false); 
                break;
            }
            i+=1;
        }
        return true;
    }
    
    bool pingGPS(bool testConds, bool runActions){
        //Variable Initialization
        int i = 0;
        fixed r;
    
        //Conditions
        if (testConds){
            if(b_isPingGPS){ //Prevents multiple instances 
                return true;
            }
            //Reset Booleans
            b_pingGPS[0] = false;
            b_pingGPS[1] = false;
            f_radiusGPS[0] = 1;
            f_radiusGPS[1] = 1;
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringExternal("NEW"));
        }
    
        //UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringExternal("RECURSE"));
    
        if( b_pingGPS[0] && b_pingGPS[1] ){
            UIDisplayMessage(PlayerGroupAll(), c_messageAreaDebug, StringExternal("RETURN"));
            //Record/Calculate Results
            b_isPingGPS = false; //Unlock 
            return true;
        }
    
        //Actions: Ping Move In/Out
        b_isPingGPS = true; //Lock
        Wait(0.0,c_timeGame);
        while( i < 2 ){
            if(!b_pingGPS[i]){
                r = f_radiusGPS[i];
                UnitSetScale(u_pingGPS[i], r*f_scaleGPS, r*f_scaleGPS, 100.0);
                libNtve_gf_ShowHideUnit(u_pingGPS[i], true);
                f_radiusGPS[i] += 0.5; //Increment
            }
            i+=1;
        }
    
        //Recursion
        TriggerExecute(TriggerGetCurrent(),false,true);
    
        return true;
    }
    
    Posted in: Galaxy Scripting
  • 0

    posted a message on Stumped by Recursion problem =(

    To whomever is able to help,

    I'm facing a recursion problem and its driving me nuts. I'd really appreciate any feedback I can get right now before I lose anymore brain cells.

    I have two triggers A and B

    A is a periodic-recursive trigger that increases the scale of my unit C until unit C collides with my cursor. B is the hit test trigger which flags true when the collision occurs.

    The algorithm is something like this:

    Code A if (B){ ANSWER = scale of unit C return true; }

    Increase scale of C

    Recurse trigger A until condition B is met.

    return true.

    THE PROBLEM Code A recurses VERY fast. In the event of a hit registering when the scale of B is 20, The actions for B cannot run unless code A has a wait of some sort. The issue here is that If i use a wait, Code A is not longer fast enough to track the scale of the unit to my cursor as fast as I can move it.

    In summary i've tried: Waits: Doesn't work because it slows down the recursion rate. Trigger Waits: Doesn't work because threads are executing too fast.. Forcing code B to run: I get an error telling me EventUnit() doesn't exist. While loop: The while loop waits for execution of code B. Doesn't work because it hangs telling me execution takes too long if I don't put a wait. (ARGH)

    Code B requires a scale increase from Code A to fire a hit event. Code A requires a hit event from B to end the recursion.

    Chicken or the egg.. Anyone have any ideas how to get around this problem? Are there any ways at all to have Code A check if Code B triggered without waits?.. This really has me stumped to the max.

    Posted in: Galaxy Scripting
  • 0

    posted a message on Create a Trigger Library.

    Hi All,

    Sorry if this has been asked already but i really can't find the answer I'm looking for with search.

    I'd actually like to create a trigger library as well. The triggers for the library are pretty much coded already, but I have no idea how to compile them into a library/resource that can be easily installed if i release it.

    Does anyone know if there is a tutorial anywhere about creating trigger libraries? And from what I've read here and there, whats up with variables getting FUBARed?..

    Posted in: Galaxy Scripting
  • To post a comment, please or register a new account.