• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

Little help with clean script

Status
Not open for further replies.
Level 13
Joined
Oct 18, 2013
Messages
692
I want a setup where when a unit enters a region, they will be given an order to a point. See bottom of post if you want a little bit more of an in-depth explantion;

I have two options as to how to do this:
1) 12 triggers (each with same/similar actions)
the only difference between these 12 would be the action, which region they are entering. The region they are sent to is a constant point, so I would like to know what I can do in JNPG possible with vJass to set up these points as constant variables.

2) One Trigger that loops through & determines which region was entered.
I don't know if this would be more efficient or not. A variation of this is that perhaps I would have Trigger1 that has the actions I want upon entering say, Regions 1,2,3,5,6,7,8. Then Trigger2 could have actions I want upon entereing 4,9,10,11,12.

Which would be more efficient? (Something else to note is that units are spawned in groups of ~3 and then sent into the grid, so maybe use a UG variable?)
If I used option 2, I would need some indexing with Point variables, so would they still be allowed to be constants?




Explanation of triggers;


[1--2--3--4 ]
[5--6--7--8 ]
[9--10-11-12]

so its a 4x3 grid. All units enter the grid through Region 1. Then, that unit is told to go to either 2 or 5, based on a roll.
IF enters 2: go to --> 3 or 6.
IF enters 5: go to--> 6 or 9.


When a unit enters an edge, they have only 1 option to advance. Examples of this are 4,9,10,11, and 12. My concept of this is still kind of fuzzy. So far ive jsut made 12 triggers, and I may keep it so if it the most efficient route to go.
Here's basically the trig;
  • Enter3
    • Events
      • Unit - A unit enters Region1
    • Conditions
    • Actions
      • Custom script: if GetRandomInt(1,2)==1 then
      • Set CasterLoc = (Center of Region2)
      • Unit - Order (Triggering unit) to Attack-Move To CasterLoc
      • Custom script: else
      • Set CasterLoc = (Center of Region5)
      • Unit - Order (Triggering unit) to Attack-Move To CasterLoc
      • Custom script: endif
      • Custom script: call RemoveLocation(udg_CasterLoc)
Is there a better function for me to call to order an Attack-Move action?
I want to remove the 4 lines of code with setting and removing the location variable, and just have, "Order unit to go to REGION2." CasterLoc is a volatile variable thats only good with no waits and stuff, so just ignore it.





*edit*
Sorry, gonna ask two in one here. If I want to get last created item, do I want to call GetLastCreatedItem, or just use bj_lastCreatedItem?
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
casterLoc is ussually named TempLocation or TempPoint (for some GUI gurus).
You can make it an array variable to have:
TempLocation1, TempLocation2, TempLocation3, TempLocation4, TempLocation5, TempLocation6, TempLocation7, etc, etc, etc, TempLocation8189, TempLocation8190 all at once. (Without spamming your global variable box.)
Just a simple way to use it, however it is bad for readability.

About the last created item, you can use either.
When you really want upmost performance, then you won't use either of them after all.
But for now, it won't matter.

About your region problem.
There are quite a few solutions to this.
First of all, your solution isn't really bad. It just isn't generic/dynamic.
A lot of things in maps can be extremely generic and are often encouraged to be so, however you won't make much generic stuff when you come to the final ends of all the lines.
You have to have some things defined (hard coded) and this comes very close to it.
It is also not a bad solution because it would work without any drawbacks.
There aren't any major glitches or bugs in it and it doesn't take a shitload of performance.

A very inituive way is to have two integer arrays (and place all 12 regions in an array ofcourse).
Then you can choose a random out of the first and second array to move to as next target.
The values in the first index would be 2 for the first array and 5 for the second array.
The values in the second index would be 3 for the first array and 6 for the second array.
The values for the tenth index would be 11 for both arrays.
Then you can simply set all those 24 values in one initialization trigger.

A better way to do this is to take it from a two dimensional array perspective.
You are in location 5, so your next location in the horizontal axis is 5+1 = 6.
The next location in the vertical axis is 5+(width) = 5+4 = 9.
Then you only have to choose which axis you want to travel on.
Ofcourse you have to define the bounds which are 4x3.
So you have to check if either bounds are met and choose the other by default.
 
Level 13
Joined
Oct 18, 2013
Messages
692
Good stuff. Yeah, using a 2D array is an option for having everything fit in 1 trigger.

About setting constant variables; Is there something in vJASS that I can use to add another globals block that I would declare constants in? Then it would just merge with the rest of the globals when the script compiles. I don't know where to look at for vjass api, but I'm almost sure something like that is implemented in vjass
*edit my bad, you just have to use globals, i thought there was something special you were supposed to use lol silly me, sadly it does seem you cant constant arrays.

About the last created item, you can use either.
When you really want upmost performance, then you won't use either of them after all.
But for now, it won't matter
Can you elaborate on that a little? :3
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You can use bj_lastCreatedItem and GetLastCreatedItem() or whatever it is called.
However, I would rather place the item inside a variable when you use CreateItem().
The only moment that you need GetLastCreatedItem() is when you create an item via a workshop in-game.
 
Level 13
Joined
Oct 18, 2013
Messages
692
Oh yeah, that makes more sense to do, thanks. This would be correct then, right?
Code:
set udg_LastCreatedItem=CreateItem(udg_Item[GetRandomInt(8,12)],GetUnitX(udg_TempUnit),GetUnitY(udg_TempUnit))
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Yes some kind of.

When you work in pure JASS, you will ussually use local variables to make your life much easier and only use globals when you use stuff like custom events.

But there is no real difference between them.
When you use GUI, you should definately use the normal "Create Item" function because that is just a GUI function. In which case, this means that you need the GetLastCreatedItem() to set the variable.

But in JASS, this is indeed a slightly more optimized version of it.
 
Status
Not open for further replies.
Top