| 03-20-2007, 09:07 PM | #1 |
Okay first, I wanted to try one of those things where you put at the top of your map and all you need to do is call it with something in the () like "call Die (unit)" and stuff like that. But because I'm not getting why it doesn't work, I'm asking for help. BTW, this is for a tower defense. JASS:function CallWave takes integer ID returns nothing local location TL = GetRectCenter(gg_rct_Top_Left) local location TR = GetRectCenter(gg_rct_Top_Right) local location BL = GetRectCenter(gg_rct_Bot_Left) local location BR = GetRectCenter(gg_rct_Bot_Right) local integer i = 0 loop exitwhen i >=5 call PolledWait (1) call CreateNUnitsAtLoc( 1, 'ID()', Player(1), TL, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, 'ID()', Player(1), TR, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, 'ID()', Player(1), BL, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, 'ID()', Player(1), BR, bj_UNIT_FACING ) set i = i + 1 endloop call RemoveLocation (TL) call RemoveLocation (TR) call RemoveLocation (BL) call RemoveLocation (BR) set TL = null set TR = null set BL = null set BR = null endfunction Basically, I'm TRYING to make it so that when I do "call CallWave (unit id)" it makes the wave by itself, using that ID. However, when I do something like JASS:function blah takes nothing returns nothing local integer ID = h00I call CallWave (ID) endfunction It doesn't work, it just gives me tons of errors. Can anyone help me and explain more about the top part of any map? Thanks in advanced ![]() P.S. I've heard that if you only declare the variable in use once in your function that you don't need the variable at all. Is that true? Thanks again! |
| 03-20-2007, 09:32 PM | #2 |
There are some random inefficiencies in your function which people will no doubt point out and thereafter rewrite the script for you. Your actual problem is: JASS:function blah takes nothing returns nothing local integer ID = 'h00I' //these 4 digit id's require single commas call CallWave (ID) endfunction |
| 03-20-2007, 09:37 PM | #3 | |
Quote:
Also change JASS:call CreateNUnitsAtLoc( 1, 'ID()', Player(1), TL, bj_UNIT_FACING ) JASS:call CreateNUnitsAtLoc( 1, ID, Player(1), TL, bj_UNIT_FACING ) ID() = call to a function named ID ' ' = integer ID = variable named ID 'ID()' = fugly code |
| 03-20-2007, 09:57 PM | #4 |
And you should either replace your JASS:call CreateNUnitsAtLoc( 1, ID, Player(1), TL, bj_UNIT_FACING ) JASS:call CreateUnitAtLoc(GetPlayerId(Player(1)), ID, LOC, bj_UNIT_FACING ) |
| 03-20-2007, 10:13 PM | #5 | |
Quote:
correction: JASS:call CreateUnitAtLoc(Player(1), ID, LOC, bj_UNIT_FACING ) JASS:native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit |
| 03-20-2007, 11:03 PM | #6 |
Okay thanks all. So to your suggestions I should change it to: JASS:function CallWave takes integer ID returns nothing local location TL = GetRectCenter(gg_rct_Top_Left) local location TR = GetRectCenter(gg_rct_Top_Right) local location BL = GetRectCenter(gg_rct_Bot_Left) local location BR = GetRectCenter(gg_rct_Bot_Right) local integer i = 0 loop exitwhen i >=5 call PolledWait (1) call CreateNUnitsAtLoc( 1, ID, Player(1), TL, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, ID, Player(1), TR, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, ID, Player(1), BL, bj_UNIT_FACING ) call CreateNUnitsAtLoc( 1, ID, Player(1), BR, bj_UNIT_FACING ) set i = i + 1 endloop call RemoveLocation (TL) call RemoveLocation (TR) call RemoveLocation (BL) call RemoveLocation (BR) set TL = null set TR = null set BL = null set BR = null endfunction JASS:function blah takes nothing returns nothing local integer ID = 'h00I' call CallWave (ID) endfunction I don't understand what you're trying to say, tamisrah. Sorry, but could you please explain more? Thanks. P.S. So...is my loop okay or not? Also, if you use a variable only once in a function is it okay to "create" it? |
| 03-21-2007, 03:31 AM | #7 |
There is nothing wrong with that, exept that I would advise you to use X/Y coordinates instead of locations. This would allow you to use the CreateUnit() native, which automatically creates 1 unit instead of N number (which you have to input in the CreateNUnitsAtLoc() call). Here's what the code would look like for that, using X/Ys, an additional loop, two array variables, and a different way of incrementing i: JASS:function CallWave takes integer ID returns nothing local location TL = GetRectCenter(gg_rct_Top_Left) local location TR = GetRectCenter(gg_rct_Top_Right) local location BL = GetRectCenter(gg_rct_Bot_Left) local location BR = GetRectCenter(gg_rct_Bot_Right) local real array x local real array y local integer i = 0 local integer i2 = 0 set x[1] = GetLocationX(TL) set y[1] = GetLocationY(TL) set x[2] = GetLocationX(TR) set y[2] = GetLocationY(TR) set x[3] = GetLocationX(BL) set y[3] = GetLocationY(BL) set x[4] = GetLocationX(BR) set y[4] = GetLocationY(BR) call RemoveLocation (TL) call RemoveLocation (TR) call RemoveLocation (BL) call RemoveLocation (BR) loop set i = i+1 exitwhen i > 5 call PolledWait (1.00) loop set i2 = i2+1 exitwhen i2 > 4 call CreateUnit(Player(1), ID, x[i2], y[i2], bj_UNIT_FACING) endloop endloop set TL = null set TR = null set BL = null set BR = null endfunction A couple other things of note:
|
| 03-21-2007, 08:04 AM | #8 | |
Pyro, your loop is wrong. You forgot the set i2=0 before the nested loop. Quote:
|
| 03-21-2007, 07:19 PM | #9 |
That you did, blu. I just happen to like rewriting scripts. Here is the correct code: JASS:function CallWave takes integer ID returns nothing local location TL = GetRectCenter(gg_rct_Top_Left) local location TR = GetRectCenter(gg_rct_Top_Right) local location BL = GetRectCenter(gg_rct_Bot_Left) local location BR = GetRectCenter(gg_rct_Bot_Right) local real array x local real array y local integer i = 0 local integer i2 = 0 set x[1] = GetLocationX(TL) set y[1] = GetLocationY(TL) set x[2] = GetLocationX(TR) set y[2] = GetLocationY(TR) set x[3] = GetLocationX(BL) set y[3] = GetLocationY(BL) set x[4] = GetLocationX(BR) set y[4] = GetLocationY(BR) call RemoveLocation (TL) call RemoveLocation (TR) call RemoveLocation (BL) call RemoveLocation (BR) loop set i = i+1 exitwhen i > 5 call PolledWait (1.00) loop set i2 = i2+1 exitwhen i2 > 4 call CreateUnit(Player(1), ID, x[i2], y[i2], bj_UNIT_FACING) endloop set i2 = 0 endloop set TL = null set TR = null set BL = null set BR = null endfunction |
| 03-21-2007, 08:03 PM | #10 |
Thanks, and yeah it's weird but I actually DO want it for player blue. Thanks for the reminder. Is it faster or just less leakier when you do it that way? EDIT: "that way" as in with the integer i2 and 2 loops. |
| 03-22-2007, 03:18 AM | #11 |
I'm not sure if using a nested loop is better, but using CreateUnit() most definitely is. X/Y values are faster than locations. |
| 03-22-2007, 03:21 AM | #12 |
Thanks again ![]() |
