SC2Mapster Forums

Development > Triggers

How to make custom 'for each'?

  • 12 posts
    #1 Feb 01, 2012 at 10:52 UTC - 0 likes

    Hi

    As topic says, how?

    #2 Feb 01, 2012 at 13:17 UTC - 0 likes

    A custom 'what'? Resource? Unit?

    And what do you mean by 'for each'? Do you need to use a loop?

    It's hard to help you out without more info ;)

    Last edited Feb 01, 2012 by Trieva
    #3 Feb 01, 2012 at 13:33 UTC - 0 likes

    'for each x' function (we are in triggers section ;) )

    i'm interested in "how/where" not how it should work because that's easy part.
    For example 'for each string "asd" in MyString' and i mean GUI implementation

    Last edited Feb 01, 2012 by Nerfpl
    #4 Feb 01, 2012 at 13:38 UTC - 0 likes

    It might be my lack of knowledge in the editor but I'm still not sure exactly what you're asking.

    #5 Feb 01, 2012 at 13:48 UTC - 0 likes
    • For each integer from x to x
    • For each player in player group

    you type 'for each' in triggers search bar and there's entire list.
    Iterate through the collection (and i don't mean array)

    Main issue is how to build it, like what's the template because in "Bult-in" lib 'for each' are blank so you can't really see the body

    Last edited Feb 01, 2012 by Nerfpl
    #6 Feb 01, 2012 at 14:00 UTC - 0 likes

    I don't know the exact template used. I can say how it should work but that's easy, like you said.

    What problems are you having from creating your custom function?

    Last edited Feb 01, 2012 by Trieva
    #7 Feb 01, 2012 at 14:08 UTC - 0 likes

    I'm guessing he can't get the "Actions" part to show up beneath it as it does with all other loops. Only recommendation I have is to look at the Galaxy code for the default loops and see if there's anything in there that would make an action definition work that way. I'll ask Küken whether he knows anything about this once I see him on skype.

    Projects: Starmon - RuneCraft
    http://i.imgur.com/G4EszBx.png

    #8 Feb 01, 2012 at 14:44 UTC - 0 likes

    - You have to create a new action and select the options "loop" and "subfunctions".

    - Add a "g" parameter to your action of type "xgroup". "xgroup" can be a group of players, a group of units, whatever group of things you want.

    - Add a "var" parameter to your action of type "x". For a group of players this would be the player id, for a group of units this would be the picked unit.

    - Add a new subfunction of type actions.

    - Then, under the custom script code field, write the following code:

    #AUTOVAR(g, xgroup) = #PARAM(g);
    #AUTOVAR(i) = 1;
    while (#AUTOVAR(i) <= PlayerGroupCount(#AUTOVAR(g))) {
        #PARAM(var) = xGroupx(#AUTOVAR(g), #AUTOVAR(i));
        #SUBFUNCS(actions)
        if (#PARAM(var) == xGroupx(#AUTOVAR(g), #AUTOVAR(i))) {
            #AUTOVAR(i) = #AUTOVAR(i) + 1;
        }
    }
    

    Note that you have to replace the xGroupx function calls inside this code to whatever function you need. This would be a playerGroupPlayer function call if you were using a player group, or a unitGroupUnit function call for an unit group.

    So, as an example, if you want to create a ForEachPlayerInGroup loop, you will have the following action declaration:

    ForEachPlayerInGroup
        Opciones: Acción, Subfunciones, Bucle
        Tipo de retorno: void
        Parámetros
            var <Cualquier variable - int>
            group = (PlayerGroupAll()) <playergroup>
        Texto gramatical: Para cada ~var|jugador~ jugador en ~group~ hacer (acciones)
        Pista: Ejecuta un bucle utilizando un valor entero. Esto ejecutará el conjunto de acciones incluido bajo la acción "Para cada jugador en un grupo" para cada jugador en el grupo jugador especificado. Por...
        Código de script personalizado
        Tipos de subfunción
            actions
    

    And the following code under the custom script code field:

    #AUTOVAR(g, playergroup) = #PARAM(group);
    #AUTOVAR(p) = 1;
    while (#AUTOVAR(p) <= PlayerGroupCount(#AUTOVAR(g))) {
        #PARAM(var) = PlayerGroupPlayer(#AUTOVAR(g), #AUTOVAR(p));
        #SUBFUNCS(actions)
        if (#PARAM(var) == PlayerGroupPlayer(#AUTOVAR(g), #AUTOVAR(p))) {
            #AUTOVAR(p) = #AUTOVAR(p) + 1;
        }
    }
    

    --------

    As a side note, these kind of actions are very useful. I use them to embed custom galaxy code inside my triggers, and to declare array sizes based on constant variables.

    Last edited Feb 01, 2012 by IliIilI


    Play CoreFight - Play CoreFight - Play CoreFight - Play CoreFight - Play CoreFight

    #9 Feb 01, 2012 at 15:04 UTC - 0 likes

    @IliIilI: Go

    That's the first time I've ever seen the # key being used in custom script. What does it do? Is it like the define statement in normal C?

    Sorry bout the off topic post =/

    Last edited Feb 01, 2012 by FuzzYD
    Works
    AoS2
    Coder
    Boss Bars+
    Custom boss bars
    GXML
    Dialog XML parser
    Project W
    Coder
    RandNAligning dialog labels

    #10 Feb 01, 2012 at 15:11 UTC - 0 likes

    @TheAlmaity: Go exactly, i mean the have part with having it as workable GUI part with actions section. In galaxy they are while's but that's the mentioned easy part :p

    @IliIilI: Go Wow thanks :) That's... i would never figure this out. So it seems those are snippets and not an actual functions

    @FuzzYD: GoFor me it seems like some macro

    Last edited Feb 01, 2012 by Nerfpl
    #11 Feb 01, 2012 at 15:14 UTC - 0 likes

    This key is only read by the the trigger editor when it translates triggers into galaxy code.

    #AUTOVAR(var, type) = value;
    

    will result into a new variable definition inside the function.

    #SUBFUNCS(actions)
    

    will add the subfunctions defined in the action trigger.

    #PARAM(var)
    

    will result into lp_var when translated to the galaxy code.

    Last edited Feb 01, 2012 by IliIilI
    #12 Feb 01, 2012 at 16:20 UTC - 0 likes

    Got it. yea! :)

    #AUTOVAR(workS,string) = #PARAM(inString);
    while(((StringContains(#AUTOVAR(workS),#PARAM(startingWith),2, true) == true) &&
    		(StringContains(#AUTOVAR(workS),#PARAM(endingWith),2, true) == true)))
    {
    	#PARAM(part) = StringReplace(#AUTOVAR(workS),"",0,StringFind(#AUTOVAR(workS), #PARAM(startingWith), true));
    	#PARAM(part) = StringReplace(#PARAM(part),"",StringFind(#PARAM(part), #PARAM(endingWith), true),StringLength(#PARAM(part)));
    	#AUTOVAR(workS) = StringReplaceWord(#AUTOVAR(workS),#PARAM(startingWith)+#PARAM(part)+#PARAM(endingWith),"",1,true);
    	#SUBFUNCS(actions)
    }
    
    Last edited Feb 01, 2012 by Nerfpl
  • 12 posts

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