need some help with spawn units trigger

afisakov

You can change this now in User CP.
Reaction score
37
I am quiet new to Jass and need some help getting the syntax right. I am trying to make a function that can conveniently create groups of units at a specified location without leaking and need some help with the syntax.
The trigger I am trying to make is the third one, first 2 just context.

I am trying to fix leaks on a map that spawns units like this
Code:
call CreateNUnitsAtLocFacingLocBJ($C,'nzom',Player(5),GetRectCenter(MB),GetUnitLoc(ev[0]))
call CreateNUnitsAtLocFacingLocBJ(3,'n006',Player(5),GetRectCenter(MB),GetUnitLoc(ev[0]))
call CreateNUnitsAtLocFacingLocBJ($A,'nzom',Player(5),GetRectCenter(pB),GetUnitLoc(ev[0]))
call CreateNUnitsAtLocFacingLocBJ(5,'n006',Player(5),GetRectCenter(pB),GetUnitLoc(ev[0]))
call CreateNUnitsAtLocFacingLocBJ($A,'nzom',Player(5),GetRectCenter(PB),GetUnitLoc(ev[0]))
call CreateNUnitsAtLocFacingLocBJ(5,'n006',Player(5),GetRectCenter(PB),GetUnitLoc(ev[0]))
Which I am pretty sure creates a large number of point and unit group leaks

my first attempt at a fix looked like
Code:
function spn0062 takes nothing returns nothing
set bj_forLoopBIndex=1
set bj_forLoopBIndexEnd=spa
loop
exitwhen bj_forLoopBIndex>bj_forLoopBIndexEnd
call CreateNUnitsAtLoc(1,'n006',Player($C),hx,90.)
call IssuePointOrderByIdLoc(bj_lastCreatedUnit,$D000F,gx)
set bj_forLoopBIndex=bj_forLoopBIndex+1
endloop
endfunction
...
set hx=GetRandomLocInRect(MB)
set gx=GetUnitLoc(ev[0])
set spa=3
call TriggerExecute (spn006m)
call RemoveLocation (hx)
set hx=GetRectCenter(pB)
it worked but was tedious since it required making a new trigger for every unit type

now I am hoping to make a more comprehensive trigger to handle all the unit types and be easier to use
I am hoping to make a trigger of the type:
Code:
function spnu takes integer spa,unittype spu,location hx,location gx returns nothing
set bj_forLoopBIndex=1
set bj_forLoopBIndexEnd=spa
loop
exitwhen bj_forLoopBIndex>bj_forLoopBIndexEnd
call CreateNUnitsAtLoc(1,spu,Player($C),hx,90.)
call IssuePointOrderByIdLoc(bj_lastCreatedUnit,$D000F,gx)
set bj_forLoopBIndex=bj_forLoopBIndex+1
endloop
endfunction
...
function main...
set spawnu=CreateTrigger()
call TriggerAddAction(spnawnu,function spnu)
however I do not know if I made this right nor do I know how to call on a trigger like this.
would I use a line like
Code:
call TriggerExecute (spawnu(10,'n006',GetRandomLocInRect(MB),GetRandomLocInRect(MC)))
? or how would I call on this? also do I remove the points in the spawn function after the endloop, or in the trigger that called on it?
Please explain how to properly implement a trigger/function like this.
 

afisakov

You can change this now in User CP.
Reaction score
37
Wow, 50 views and no responses.
Is my post too long or is it that hard a problem to solve?

The abridged version:
I want to make a function that takes a location, unit type, and integer;
and then spawns the specified number of units of that type at the location without leaking

I made an attempt to create the function but don't know how to call on it and am not sure if I did it properly.

If it is not possible to make a function/trigger like this please let me know so I can stop monitoring this thread.
 

afisakov

You can change this now in User CP.
Reaction score
37
I am getting really tired of it duplicating all my posts...
I know I lag a bit on this site but it shouldn't be this bad.
btw, can a mod delete this post.
 

Tyrulan

Ultra Cool Member
Reaction score
37
Hi afisakov,

Unfortunately a lot of the active members on this site no longer monitor the Wc3 JASS forums, so help with more difficult problems is few and far between. But I will do what I can.

It sounds like you want to make a wrapper around the CreateNUnitsAtLocFacingLocBJ. This means that your wrapper function will take the same parameters, plus the additional parameters that you need, such as unit id.

Also, when using built in BJ functions, they clean up leaks pretty well, except they leave one or two for you to handle.

Following the code we see that CreateNUnitsAtLocFacingLocBJ calls on this code:

JASS:
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction

You will need to set the bj_lastCreatedUnit to null and use the GroupClear function on bj_lastCreatedGroup.

Executing a trigger manually suggests to me that you've already received an event elsewhere, and would like to call upon a more global function to use frequently. I recommend writing your wrapper function in the global function space provided in the World Editor.
 

Tyrulan

Ultra Cool Member
Reaction score
37
Continuing,

Typically, one nullifies variables in the calling function, and not inside the function they were passed to.

If I were to write some code like so:
JASS:
local integer x = 15
call SomeFuncitonThatNullifiesX(x)
call SomeFunctionThatUsesX(x)

Of course our integer x would be null, and unusable in "SomeFunctionThatUsesX." It makes more sense to modify the above to look like so:
JASS:
local integer x = 15
call SomeFuncitonThatUses(x)
call SomeOtherFunctionThatUsesX(x)
set x = null

I hope this make things more clear for you.

Let me know if you need more help with this.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top