| 04-12-2008, 12:43 AM | #1 |
im super new to jass (started learning today) i made a trigger to move a unit to a region, and then i learned about memory leaks so i tried to eliminate it, but the trigger wont work properly. it does everything except move the unit? whats wrong with it :( JASS:function Trig_Capture_Actions takes nothing returns nothing set tempPoint = GetRectCenter(gg_rct_belt) call SetUnitOwner( GetSpellTargetUnit(), GetTriggerPlayer(), false ) call AddSpecialEffectLocBJ( GetUnitLoc(GetSpellTargetUnit()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call SetUnitPositionLoc( GetSpellTargetUnit(), udg_tempPoint ) call RemoveLocation ( udg_tempPoint ) endfunction it doesnt do much because im just playing around with things at the moment. and i cant find any guides that help, all use center of (playable map area) and the same script for that wont work for me so i assume its something different for regions.. |
| 04-12-2008, 12:52 AM | #2 |
Here is your problem JASS:function Trig_Capture_Actions takes nothing returns nothing set tempPoint = GetRectCenter(gg_rct_belt) call SetUnitOwner( GetSpellTargetUnit(), GetTriggerPlayer(), false ) call AddSpecialEffectLocBJ( GetUnitLoc(GetSpellTargetUnit()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call SetUnitPositionLoc( GetSpellTargetUnit(), udg_tempPoint ) call RemoveLocation ( udg_tempPoint ) endfunction Those 2 variables are different, the proper working version is this JASS:function Trig_Capture_Actions takes nothing returns nothing set tempPoint = GetRectCenter(gg_rct_belt) call SetUnitOwner( GetSpellTargetUnit(), GetTriggerPlayer(), false ) call AddSpecialEffectLocBJ( GetUnitLoc(GetSpellTargetUnit()), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call SetUnitPositionLoc( GetSpellTargetUnit(), tempPoint ) call RemoveLocation ( tempPoint ) endfunction Also your code is very efficient, as you can see you are calling the same function multiple times, and each time it will return the same variable. Doing something like this will make it much more efficient JASS:function Trig_Capture_Actions takes nothing returns nothing local unit target = GetSpellTargetUnit() set tempPoint = GetRectCenter(gg_rct_belt) call SetUnitOwner( target, GetTriggerPlayer(), false ) call AddSpecialEffectLocBJ( GetUnitLoc(target), "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl" ) call SetUnitPositionLoc( target, tempPoint ) call RemoveLocation ( tempPoint ) endfunction There are many other things you need to do that you have to learn, such as using x,y co-ordinates instead of locations (or points as they are reffered to in GUI). Also using 99% of BJ functions is pointless, since they just call themselves, for example AddSpecialEffectLocBJ is just JASS:function AddSpecialEffectLocBJ takes location where, string modelName returns effect set bj_lastCreatedEffect = AddSpecialEffectLoc(modelName, where) return bj_lastCreatedEffect endfunction So really you can replace AddSpecialEffectLocBJ with AddSpecialEffectLoc and then finally when you learn to use x/y you will use AddSpecialEffectTarget |
| 04-12-2008, 02:33 AM | #3 |
ty for the help <3 i tried to do everything you said (except for the points) the code you gave me didnt work untill i added in local location tempPoint did i do something wrong or is that supposed to be there? JASS:function Trig_Capture_Actions takes nothing returns nothing local location tempPoint local unit target = GetSpellTargetUnit() local effect capture set tempPoint = GetRectCenter(gg_rct_belt) call SetUnitOwner( target, GetTriggerPlayer(), false ) set capture = AddSpecialEffectLoc( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", GetSpellTargetLoc()) call SetUnitPositionLoc( target, tempPoint ) call TriggerSleepAction( 2 ) call DestroyEffect( capture ) set target = null set capture = null call RemoveLocation ( tempPoint ) endfunction this 1 works perfectly. is it good/effiencent (not including the no points) i try and be quick learner but can only go so fast.. *edit* i think i missed a leak on the unit x.x. trying 2 fix but idk *edit*would this be MUI? |
| 04-12-2008, 04:40 AM | #4 |
You forgot set tempPoint = null, so you're leaking a variable there. Everything else looks good though. I could make your code bit there use x/y if you'd like, so you can see how it should look. Also: JASS:local location tempPoint = GetRectCenter(gg_rct_belt) local effect capture = AddSpecialEffectLoc("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", GetSpellTargetLoc()) PS: There's no leak on the unit, just on the location. And yes, it's MUI. Here's your code, all fixed up and ready to go. JASS:function Trig_Capture_Actions takes nothing returns nothing local real x = GetRectCenterX(gg_rct_belt) local real y = GetRectCenterY(gg_rct_belt) local unit target = GetSpellTargetUnit() local effect capture = AddSpecialEffect( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", x, y) call SetUnitOwner( target, GetTriggerPlayer(), false ) call SetUnitPosition( target, x, y ) call TriggerSleepAction( 2 ) call DestroyEffect( capture ) set target = null set capture = null endfunction |
| 04-12-2008, 06:28 AM | #5 |
set tempPoint = null isnt the same as call RemoveLocation ( tempPoint )? and thx for the other advice |
| 04-12-2008, 07:41 AM | #6 |
No it isnt setting handle to nulls just recycle's there index, of which if you never do you probably never notice anything unless you use systems that are reliant on the handle index's recycling eachother. On the other hand RemoveLocation actually removes the handle from the game, where as setting a handle to null just removes the index that is pointing to the handle |
| 04-12-2008, 08:02 AM | #7 |
why is using coordinates better if you already have the region there? (im comming as an old SC map maker, so im use 2 regions/locations for everything...) and in darkwulf's code, will i have to fix leaks on x,y or do they not leak and thats why they are good? |
| 04-12-2008, 08:17 AM | #8 |
Any variable that isn't a handle (real, integer, boolean) doesn't leak and that is one reason why x/y (which are reals) co-ordinates are always used because you don't have to worry about cleaning them. The only exception is strings, but they always leak (you cant do anything about it). However strings do get recycled and the leak is absolutely minimal, you would have to play a map for a week straight to notice anything Another reason using x/y co-ordinates is much more efficient then using points aka locations, since locations are a handle they take up more memory then just the x/y co-ordinates combined and the functions that are used to alter/retrieve data about locations are less efficient then the ones using x/y |
| 04-12-2008, 08:23 AM | #9 |
so the best would be deleting the region entirely (since i only needed it for the points) and have the trigger go directly to the points of it (gathered from pointing the mouse close enough to the center of the region in the world editor and using this coordinates? and in starcraft you could do things w/ forces. like i dont want this spell to effect anyone in a certain force. i dont see anything for that in warcraft, like condition>targeted player is no on force 1, does it lack this? *edit* nvm, i thought of a way around it for my map. but it would still be good 2 have force related conditions.. |
| 04-12-2008, 08:28 AM | #10 |
You can do much more things then just forces in Wc3 if GetUnitState(u,UNIT_STATE_MAX_LIFE) > 100 then will mean that it will only effect units that have more then 100 life Wc3 has many many many more options then SC in terms of JASS. |
| 04-12-2008, 08:38 AM | #11 |
too many imo. SC was simple, but anyone could figure it out easily and always find a way to do something - even with the GUI. i used starforge ripped through that script, but also IMO starforge was better written/easier/more user friendly/faster then world edit. i wish someone would make a warforge... world editor just is too sloppy and unorganized nvm the thing i wanted didnt work at all so im back 2 semi/completly lost |
| 04-12-2008, 08:45 AM | #12 |
Not too many, just too disorganized and WE GUI editor is just total crap |
| 04-12-2008, 09:00 AM | #13 |
heres the completle thing (yes its pokemon but i figured it was a good way 2 learn, you get item spells, unit spells, hero spells, lots of simple triggers to work with and iv learned a lot just doing it) note: this is still my first trigger i ever did. i felt accomplished when i finished it the first time, all it did was issue a thunderclap under the casting hero x.x . i cant make it so it wont effect human-controlled units. i tried making the conditions caster is an anchient (the 'trainer' to avoid pokemon from using pokeballs) ability cast = "catch" and the target of the spell = computer. but it doesnt work x.x; JASS:function Trig_Capture_Conditions takes nothing returns boolean if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true ) ) then return false endif if ( not ( GetSpellAbilityId() == 'AIfz' ) ) then return false endif if ( not ( GetSpellTargetUnit() == MAP_CONTROL_COMPUTER ) ) then return false endif return true endfunction function Trig_Capture_Actions takes nothing returns nothing local unit target = GetSpellTargetUnit() local real x = GetRectCenterX(gg_rct_Pokebelt) local real y = GetRectCenterY(gg_rct_Pokebelt) local effect capture = AddSpecialEffectLoc( "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", GetSpellTargetLoc()) call SetUnitOwner( target, GetTriggerPlayer(), false ) call SetUnitPosition( target, x, y ) call TriggerSleepAction( 2 ) call DestroyEffect( capture ) set target = null set capture = null endfunction //=========================================================================== function InitTrig_Capture takes nothing returns nothing set gg_trg_Capture = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Capture, EVENT_PLAYER_UNIT_SPELL_CAST ) call TriggerAddCondition( gg_trg_Capture, Condition( function Trig_Capture_Conditions ) ) call TriggerAddAction( gg_trg_Capture, function Trig_Capture_Actions ) endfunction i know i have a BJ function in there call TriggerRegisterAnyUnitEventBJ( gg_trg_Capture, EVENT_PLAYER_UNIT_SPELL_CAST ) is there a list of all the bj's and the natives i think its called? i tried 2 find as much stuff as i could and put them in a txt file of mine for easier access, stuff like unit attachment points, variables and what they do, good units/items to base things off of, and a helpfull list of GUI-Jass translations of attack type/integers/points and location/unit/unit group |
| 04-12-2008, 09:08 AM | #14 |
That looks good, the only things that need improvements is this JASS:function Trig_Capture_Conditions takes nothing returns boolean if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) == true ) ) then return false endif if ( not ( GetSpellAbilityId() == 'AIfz' ) ) then return false endif if ( not ( GetSpellTargetUnit() == MAP_CONTROL_COMPUTER ) ) then return false endif return true endfunction Can be written as JASS:function Trig_Capture_Conditions takes nothing returns boolean local boolean b = false set b = IsUnitType(GetTriggerUnit(), UNIT_TYPE_ANCIENT) set b = GetSpellAbilityId() == 'AIfz' set b = GetSpellTargetUnit() == MAP_CONTROL_COMPUTER return b endfunction |
| 04-12-2008, 09:17 AM | #15 |
iv read just about every guide that came up for searching jass is any thing that can search, and not 1 was really any helpfull.. is there a list of things like bjfunctions and what there natives are? because im goign 2 start on my own guide 2 jass. learn enough through help of other people to be able to trial / error thnigs untill you know it.. thats how i did it with starcraft and thats probably the best way here :D its better then posting everytime you hit a road block but since i havnt reached the point of knowing yet, will the change you made make the code work? when i look at it, it looks like it should and tells me it should x.x but it does not.. |
