SC2Mapster Forums

Development > Triggers

Create Unit always X spaces from another [SOLVED]

  • 16 posts
    #1 Apr 01, 2012 at 20:42 UTC - 0 likes

    not real familiar with custom scripting yet, but I'm looking to create/move unit X at say coordinates (A,B). Once that unit is created, i want to create/move unit Y to (A+4, B).

    How do i do this?

    #2 Apr 01, 2012 at 21:11 UTC - 0 likes
    Global Variables:                        // create outside of trigger (no local variables)
        distance_X = 0                       // integer variable
        distance_Y = 0                       // integer variable
    
    Actions:
        General - Repeat (10) times          // or use another loop action
            Unit - Create Unit of Type (X) at point (A + distance_X,  B + distance_Y)
            Variable - distance_X + 4
            Variable - distance_Y + 4
    

    This should work - if not just tell me :P

    #3 Apr 01, 2012 at 21:23 UTC - 0 likes

    so if i start creating triggers, units, etc via script editor, do they show up in the gui?

    Where do i define this? I can't really follow the logical flow by looking at the actual script editor. I would "expect" to see all variables defined, then functions, then other declarations, then the code body.

    What you say makes easy sense, i just don't understand the "where" of defining this.

    #4 Apr 01, 2012 at 21:26 UTC - 0 likes

    Do you mean script in text form with "script editor" or the trigger GUI of the editor?

    #5 Apr 01, 2012 at 21:32 UTC - 0 likes

    script in text.....really all i'm trying to do for now is (in somewhat psuedocode):

    function create() {
    put unit at x,y
    put unit2 at x+4,y
    put unit3 at x+8,y
    }

    Then a trigger that will call this function over and over when certain conditions happen.  Basically i'm creating a room and moving it.

    Last edited Apr 01, 2012 by basballguy
    #6 Apr 01, 2012 at 21:40 UTC - 0 likes

    Well I never used galaxy script, so I guess I can't help you with that :(
    The code I posted was GUI script.

    maybe try it here

    #7 Apr 01, 2012 at 21:43 UTC - 0 likes
    Quote from Ousnius: Go

    Well I never used galaxy script, so I guess I can't help you with that :( The code I posted was GUI script.

    maybe try it here

    What's the difference between GUI script and galaxy script?

    #8 Apr 01, 2012 at 21:57 UTC - 0 likes

    This - (random pic)
    and
    that - (random pic) :)

    (Graphical User Interface (GUI)-Scripting and pure Text-Scripting)

    Last edited Apr 01, 2012 by Ousnius
    #9 Apr 01, 2012 at 21:58 UTC - 0 likes

    Something like

        Local Variables
            _X = 0.0 <Real>
            _Y = 0.0 <Real>
            initial point = (Bottom-left of (Entire map) bounds) <Point>
            temp point = No Point <Point>
        Actions
            General - For each real _X from 1.0 to 100.0 with increment 4.0, do (Actions)
                Actions
                    General - For each real _X from 1.0 to 100.0 with increment 4.0, do (Actions)
                        Actions
                            Variable - Set temp point = (Point(((X of initial point) + _X), ((Y of initial point) + _Y)))
                            Unit - Create 1 Marine for player 1 at temp point using default facing (No Options)
    

    This will create units in range of X 100 and Y 100 offset by 4.
    Those units won't show in Editor obviously as map script runs at runtime.
    Create Unit = Spawn unit. You create new unit kinds in Data editor if that's what you mean

    Quote from basballguy: Go

    What's the difference between GUI script and galaxy script?

    • GUI , as name says (Graphic user interface), allows to "write" code via interface without really typing anything (more like clicking around). It's safer and more readable for beginners.
    • Galaxy script is code behind GUI. It can be viewed by clicking (in triggers editor) Data -> View script. You can also write code directly in Galaxy script in C-like syntax. For this refer to Galaxy tutorials
    Last edited Apr 01, 2012 by Nerfpl
    #10 Apr 01, 2012 at 22:09 UTC - 0 likes

    can you drect me to a tutorial that talks through loops? I"m having a difficult time translating my programming knowledge to the SC2 editor and galaxy script.

    #11 Apr 01, 2012 at 22:16 UTC - 0 likes

    Generally GUI is refereed to as 'Triggers" and code as "Galaxy"

    About the loops. Entire Galaxy as i mentioned is very C-like but with very limited functionality so loops are 'while'. There's no 'for' i believe. GUI says 'for' but in code behind it's actually while loop
    something like

    while(i<max)
    {
      //do something
      i=i+1;
    }
    
    Last edited Apr 01, 2012 by Nerfpl
    #12 Apr 01, 2012 at 23:06 UTC - 0 likes

    slowly figuring this out. Can I also (for any point/unit) get the coordinates and assign the X and Y to separate variables?

    Last edited Apr 01, 2012 by basballguy
    #13 Apr 01, 2012 at 23:46 UTC - 0 likes

    you can
    point p = location of unit
    real x = x of point p
    real y = y of point p

    real is GUI name for galaxy fixed

    there's a lot of stuff like that. That's why you should use GUI - to learn API as it's quite user friendly. If you create for example variable of type <real> and try to assign something to it, in 'functions' section you have all functions with return type <real> categorized and mostly described

    Last edited Apr 01, 2012 by Nerfpl
    #14 Apr 01, 2012 at 23:58 UTC - 0 likes

    <<reply 626366>>

     // Variable Declarations
        point lv_p;
        fixed lv_d_x;
        fixed lv_d_y;

        // Variable Initialization
        lv_p = PointFromId(25);
        lv_d_x = x of p;
        lv_d_y = y of p;

    this errors out....maybe i'm taking what you say too literal

    I"m ok with using the GUI until i get the hang of it...

    edit:  I defined these variables via the GUI and got the syntax error on the d_x and d_y initializations.

    Last edited Apr 02, 2012 by basballguy
    #15 Apr 02, 2012 at 00:05 UTC - 1 like

    that's how it looks in galaxy

        lv_p = UnitGetPosition(SomeUnit);
        lv_x = PointGetX(lv_p);
        lv_y = PointGetY(lv_p);
    

    but you may skip lv_ part if you write in code. Is just for trigger editor to prevent global/local name collision (i guess that's the reason)

    Last edited Apr 02, 2012 by Nerfpl
    • 1.jpg
    • 2.jpg
      or
    #16 Apr 02, 2012 at 01:24 UTC - 0 likes

    Thanks for all the help.

    I am now able to generate units and continuously (and randomly) spawn them at multiple locations.  Appreciate all the help

  • 16 posts

You must login to post a comment. Don't have an account? Register to get one!