SC2Mapster Forums

Development > Triggers

I need a function for set variable

  • 12 posts
    #1 Jan 10, 2013 at 23:54 UTC - 0 likes

    Hey guys,

    I want to start off by saying I do not, sadly, know any languages. I am however, familair with 'how' they are written. With that being said:

    I want a trigger to fire when a unit enters a region.. but not just one region, 50+ different ones. I assume the easiest way to do this is with a function (such as blizzard's triggering(player, region, unit), but I can't seem to figure out how to do it efficiently (to keep the map size/load small).

    Here's an example:
    Events:
      Unit - Any unit enters (region)
    Do actions.

    But, because I have a bunch of regions, let's call them Region1-50, the only way I've found to do it is as follows:
    Events:
       Unit - Any unit enters (Region1)
       Unit - Any unit enters (Region2)
       Unit - Any unit enters (Region3)
       etc
    Do actions.

    For the latter example, I have a global variable I predefined (50 times, ugh) to an array myArrayRegions[].
    In my code, I added a for loop to help save a bunch of triggers, it looks like this:
    Events:
       Unit - Any unit enters (Region1)
       Unit - Any unit enters (Region2)
       Unit - Any unit enters (Region3)
       etc
    Actions:
       For i 1 to 50 with increment 1, do actions.
         Actions:
           if Triggering Region = myArrayRegions[i]
             Do actions.

    This code sucessfully checks that the unit that entered one of the 50 listed regions is equal to one of the regions listed, then executes the code. I scripted it like this, because I thought it would be more efficient than writing 50 triggers (one for each region)

    Which brings me to my problem..
    I would love a function that I can use for this map (and any other ones I make), that assigns the variables' values. i.e

    for i 1 to 50 with increment 1
       myArrayRegions[i] = RegionFromId(i); //assuming I know the specific region Id, and can edit them to be incremental of eachother.

    That should declare my array to all the regions for me. With two simple for loops, one declaring my variables in the array, and one checking if they are equal to a triggered region, I would save a lot of triggers.

    I'm also all ears to find another way to do actions when a unit may enter a large quanity of regions.
    I hope this makes sense, and I hope someone else finds this useful.

    Thanks in advance,
    -nooblark

    **EDIT**
    I would ideally love a function that sets my variables with a loop.
    A bonus would be some way of calling that array (with all its values ( [1] - [50] ), as one event.

    Last edited Jan 10, 2013 by nooblark
    #2 Jan 11, 2013 at 06:17 UTC - 0 likes

    Looks like your part way there. You'll actually not want to use a trigger at all. First you have to assign each of the regions to an integer in a global array in your init trigger; there is no way around this, you have to predefine it. Then instead of using a "unit enters" event and trigger, create a custom action definition that runs a loop everyone once in a while like .1 sec and check if the unit in the region within an integer loop.

    Last edited Jan 11, 2013 by hobbidude

    When I want your opinion...I'll give it to you!

    http://www.sc2pod.com/achievement.php?id=13361

    #3 Jan 11, 2013 at 15:07 UTC - 0 likes

    something you could do for a small number of units, but not for a full fledged melee map..
    while
      if  unit (whatever unit it is, could event be a variable that got assigned to the unit upon birth in the same trigger) is alive == true
       actions
            while unit is in region[1] ==false
              actions
               run whatever you want to happen here ex; run grant player 50$
                wait for condition
                 if
                    unit in region[1] == false
    why use this then?
    because it allows you to customize for each region and amount of regions. you could even customize for the type of unit or another factor by adding a switch up there that switches based on the factor you want a change on
    why can't i be clever use event like unit enters region circle( point[1], 1.0)
    because event are based off of how things are declared at the initialization of the map. so while you can make the above event it will only get you nowhere, because default setting for points are no point. or if you do set it for a point it will only work for that one point. and if you want to do multiple points you are better off just setting it up like you did earlier.

    Last edited Jan 14, 2013 by willuwontu

    I'm a triggerer
    I can't make awesome terrains
    I dabble in data

    I suck at poems
    That is why i do haiku
    i suck at them too :(

    #4 Jan 13, 2013 at 01:55 UTC - 0 likes

    Quote from hobbidude:
    Looks like your part way there. You'll actually not want to use a trigger at all. First you have to assign each of the regions to an integer in a global array in your init trigger; there is no way around this, you have to predefine it. Then instead of using a "unit enters" event and trigger, create a custom action definition that runs a loop everyone once in a while like .1 sec and check if the unit in the region within an integer loop.
    ----

    Thanks for that info. I skipped the very basics of the editor. I'm not sure if creating functions/actions are advanced or basic, but I tried to mess around with creating a new function, but it was a little out of my league. Are there any good tuturials you know of that consists of all the 'advanced' triggering (such as creating own functions/actions/etc.), or even custom scripting (I feel as though the GUI makes doing it more complicated to do that stuff)?

    I understand I have to predefine everything too, but I was wondering if there was a faster way, such as setting a loop like this:
    Variable: x=001
    Variable: area[] = array of regions

    For (var i=0; i < 50; i++)
       area[i] = regionFromId('region' + x)
       x = x+1

    That would set area[0] = to region001, then add one to each (area[1], region002).
    As stated in my first post, I understand programming a little, so I am just assuming you can add a string and an int to form a return to the function that is able to be called.

    If you set a variable the normal way, using the GUI, and go into the script page, it actually just coded it like area[0] = regionFromId(region001), so I didn't know if I was able to copy and paste that and just change the one number, or even set it up with some weird loop to do it, as described above. (I 'm also pretty sure x=001 is not a valid 'int' number for that, but it was written like that to give a quick, and easy to read, example of what it would be doing).

    Thanks for the info,
    -nooblark

    **Edit**
    By skipped basics I mean I am highly confused about maps versus mods, sizes and lag. I finished my first map recently, but I'm not publishing it until I'm 100% confidient it is what I want. I don't want to be another person who uploaded a bad map on battle net that got played and forgotten.

    Perhaps someone who feels like answering a few dumb questions with that regard can PM me :)

    Last edited Jan 13, 2013 by nooblark
    #5 Jan 13, 2013 at 02:17 UTC - 0 likes

    I highly suggest that you go onto sc2mapster's IRC channel. (Freenode, #sc2mapster)

    The easiest way that I could see you doing this is by having all the regions in an array to start. Then you wanna select all the regions, copy-paste into the same exact spot and merge them all into one region. That is to say that you have your 50 regions, then one region that is like all of them combined. In that case, you only have one "Unit Enters Region" action and you can iterate through the array to figure out which one it is.

    EDIT:: Also, if this isnt the question you were asking, it might be because I didnt read the whole OP. :)

    Last edited Jan 13, 2013 by Shawn91210
    #6 Jan 13, 2013 at 02:34 UTC - 0 likes

    Quote from Shawn91210:
    I highly suggest that you go onto sc2mapster's IRC channel. (Freenode, #sc2mapster)

    The easiest way that I could see you doing this is by having all the regions in an array to start. Then you wanna select all the regions, copy-paste into the same exact spot and merge them all into one region. That is to say that you have your 50 regions, then one region that is like all of them combined. In that case, you only have one "Unit Enters Region" action and you can iterate through the array to figure out which one it is.

    EDIT:: Also, if this isnt the question you were asking, it might be because I didnt read the whole OP. :)
    ----

    I like that idea! That will help take the 50 events out of my trigger. I think my whole map was made with 8 triggers, and I'm still looking to consolidate them.

    The OP was with regards to adding all the regions to the array easily. Instead of doing:
    Array[0] = region001
    Array[1] = region002
    Array[2] = region003
    ...
    Array[49] = region050

    to do something like:
    Array[i] = RegionFromId(i)   //since the code actually is RegionFromId(), I didn't know if it was possible to put a variable combination of string + int to equal region001, region002, etc., rather than typing it 50 times in the initial define process.

    #7 Jan 13, 2013 at 02:38 UTC - 0 likes

    I'm making another reply, since this is another question, and I feel like the questions keep getting lost in my understanding/questioning examples/paragraphs.

    Is it bad to have a trigger for unit enter region for any spot on the map? I feel like the trigger would be called too many times (though it may get called, it won't neccesarily perform actions (depending on the conditions/etc)).

    #8 Jan 13, 2013 at 02:44 UTC - 0 likes

    I dunno. The only time I've needed a region array was when I was making a grid of regions, and in that case I made all the regions via triggers and just set them to the array in the loop that was creating them. I don't know if your situation is similar so you may need to just set them all by hand, but you'd only have to do it once.

    As for the other question, I'd just go with whichever you feel works better. Even if you find out later that it lags, you can always change it to something else. That's just my opinion though.

    #9 Jan 13, 2013 at 20:37 UTC - 0 likes

    I do not know if you find this as a solution, but if all the regions are meant to do the same, you can combine them to one, the function is named Selection Merge (if you check configure controls). The defualt hotkey is numpad 0.

    This will combine all the regions you have selected, into one region.

    So this will make it easier for you as far as I can see.

    #10 Jan 14, 2013 at 07:02 UTC - 0 likes
    Quote from nooblark: Go

    I'm making another reply, since this is another question, and I feel like the questions keep getting lost in my understanding/questioning examples/paragraphs.

    Is it bad to have a trigger for unit enter region for any spot on the map? I feel like the trigger would be called too many times (though it may get called, it won't neccesarily perform actions (depending on the conditions/etc)).

    Yes, you are correct it can be troublesome to use events especially with a lot of units; I already suggested the correct way to do this in my first reply.

    Last edited Jan 14, 2013 by hobbidude
    #11 Jan 16, 2013 at 15:40 UTC - 0 likes

    I do not believe that Array[i] = RegionFromId(i) is possible. At some point you will have to physically set them to variables somewhere.

    #12 Jan 16, 2013 at 17:29 UTC - 0 likes
    Quote from playpong: Go

    I do not believe that Array[i] = RegionFromId(i) is possible. At some point you will have to physically set them to variables somewhere.

    It is possible as long as the Region IDs are correct. In general I would not recommend using this solution since it might cause bugs once accidently changing region IDs.

    http://i55.tinypic.com/wio5t0.jpg

    Starcraft Universe lead programmer

  • 12 posts

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