HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[JASS] Why does this script stop?

06-13-2011, 01:31 PM#1
Idontneedaname
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)

Collapse 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
Attached Files
File type: w3xFünfeck.w3x (18.0 KB)
06-13-2011, 09:33 PM#2
Captain Griffen
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.
06-13-2011, 09:37 PM#3
Idontneedaname
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!)
06-13-2011, 09:38 PM#4
BBQ
Yes, division by zero kills the thread.
06-13-2011, 10:25 PM#5
BBQ
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.