Wc3C.net [JASS] Why does this script stop?
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

 06-13-2011, 01:31 PM #1 Idontneedaname User     Join Date: Nov 2008 Posts: 61 Submissions (1) [JASS] Why does this script stop? I have made a spell which should create an n-gon around the caster. But the script stops after the second corner for every n. Why is that? (you can change the n in the trigger, it will change the number of sides) JASS:```function floor takes real r returns real return R2I(r) //Yes, it's not needed. So what? endfunction function Create takes nothing returns nothing local location loc local integer n = 3 local real a = 500. local real angle = udg_Winkel*bj_DEGTORAD local real pi = bj_PI local real r = angle + ((pi - (2*pi/n))*floor(n*angle/(2*pi))) local real r1 = Sin(r) local real r2 = Sin((pi/2) + (pi/n) - r) local real dist = SquareRoot(((a*a*r1*r1)/(r2*r2))+(a*a)-((2*a*a*r1*Cos(((n-2)*pi)/(2*n)))/r2)) local real x = GetUnitX(udg_caster) + dist * Cos(angle) local real y = GetUnitY(udg_caster) + dist * Sin(angle) call CreateUnit(Player(0), 'h000', x, y, 0.00) set udg_Winkel = udg_Winkel + 2. call DisplayTextToPlayer(Player(0), 0.00, 0.00, R2S(udg_Winkel)) if udg_Winkel == 360. then call PauseTimer(GetExpiredTimer()) call DestroyTimer(GetExpiredTimer()) endif endfunction function Trig_Init_Conditions takes nothing returns boolean if GetSpellAbilityId() == 'AHpx' then return true endif return false endfunction function Trig_Init_Actions takes nothing returns nothing local timer t = CreateTimer() set udg_caster = GetSpellAbilityUnit() call TimerStart(t, 0.01, true, function Create) endfunction //=========================================================================== function InitTrig_Init takes nothing returns nothing set gg_trg_Init = CreateTrigger( ) call TriggerRegisterAnyUnitEventBJ( gg_trg_Init, EVENT_PLAYER_UNIT_SPELL_CHANNEL ) call TriggerAddCondition( gg_trg_Init, Condition( function Trig_Init_Conditions ) ) call TriggerAddAction( gg_trg_Init, function Trig_Init_Actions ) endfunction ``` Fünfeck.w3x __________________ Thanks to Neonex for the idea. Last edited by Idontneedaname : 06-13-2011 at 01:33 PM.
06-13-2011, 09:33 PM   #2
Captain Griffen

Content Director

Join Date: Sep 2003
Posts: 5,375

Submissions (2)

My guess would be r2=0, so divide by 0, but I cba to sort through all those horrible maths functions going from degrees to radians to degrees.
__________________
Quote:
 Originally Posted by Earth-Fury Griffen is correct, you are not.
Quote:
 [13:32] hmm.. stil i want to have some unused women

 06-13-2011, 09:37 PM #3 Idontneedaname User     Join Date: Nov 2008 Posts: 61 Submissions (1) yes, the math is nice, isn't it? So you say that a function can indeed stop at a division by zero? Here is an example for what happens for n = 3: what confuses me is that the first corner works just fine (for every n!) __________________ Thanks to Neonex for the idea. Last edited by Idontneedaname : 06-13-2011 at 09:38 PM.
 06-13-2011, 09:38 PM #4 BBQ User   Join Date: May 2011 Posts: 85 Submissions (2) Yes, division by zero kills the thread.
 06-13-2011, 10:25 PM #5 BBQ User   Join Date: May 2011 Posts: 85 Submissions (2) Heck, I read your code thoroughly and I couldn't see where the issue is. There is evidently no division by zero. Anyway, I decided to test it, and it actually works as it should. No idea what's up with your map, as I can't open it (it's corrupted), but I can tell you that your code can only work with one instance, as it's not multi-instanceable due to those globals. Last edited by BBQ : 06-13-2011 at 10:27 PM.