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.
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.
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.
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 :)
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. :)
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.
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)).
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.
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.
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.
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.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
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.
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.
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.
Still alive and kicking, just busy.
My guide to the trigger editor (still a work in progress)
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 :)
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. :)
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.
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)).
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.
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.
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.
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.