• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] JASS question! need HELP

Status
Not open for further replies.
Level 8
Joined
Mar 23, 2007
Messages
302
Hi

Here i have a problem.
this thing just dont work....
can some one help me

i want to get every 0.33 (in this example every 5) seconds the distanze.
JASS:
function Trig_MovedWay_Actions takes nothing returns nothing
local group G = GetUnitsInRectMatching(GetPlayableMapRect(), null)
local unit g = FirstOfGroup(G)
local real x
local real y
local real xold
local real yold
local real xd
local real yd
local real Way
loop
set g = FirstOfGroup(G)
exitwhen g == null
set xold = GetHandleReal(g, "x")
set yold = GetHandleReal(g, "y")
set x = GetUnitX(g)
set y = GetUnitY(g)
set xd = x - xold
set yd = y - yold
set Way = SquareRoot(xd*xd+yd*yd)
call SetHandleReal(g, "x", x)
call SetHandleReal(g, "y", y)
call GroupRemoveUnit(G,g)
endloop
call DestroyGroup(G)
set G = null
set g = null
endfunction

//===========================================================================
function InitTrig_MovedWay takes nothing returns nothing
    set gg_trg_MovedWay = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_MovedWay, 5 )
    call TriggerAddAction( gg_trg_MovedWay, function Trig_MovedWay_Actions )
endfunction
 
Level 6
Joined
Jun 30, 2006
Messages
230
Well... you are attaching the real to a unit which is removed... so you aren't calling the same unit on the next iteration.
JASS:
call SetHandleReal(g, "x", x) //you set here
call SetHandleReal(g, "y", y) //and here
call GroupRemoveUnit(G,g) //then remove here

You need to attach the data to something else besides the unit. I've never tried it before, but I think you can attach to a group.
Misread a few things.

Also, your logic is all messed up, I think. You pick every unit on the map, grab its x,y and then set Way equal to something... but it gets reset each iteration of the loop? What good does that do? You don't do anything with it.

Also, running this at .33 will be pretty taxing if there are a lot of units on the map...
 
Level 8
Joined
Mar 23, 2007
Messages
302
no, this does not help me.
mb u have some other ideas where the problem is...
i just drive insane with this.
And what i notized, after deleting some parts and testing again and again, i know that the problem is with the grouping part, not the handle vars.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Also, your logic is all messed up, I think. You pick every unit on the map, grab its x,y and then set Way equal to something... but it gets reset each iteration of the loop? What good does that do? You don't do anything with it.

Maybe in his code he put there actions ?

Anyway, you can't attach info with localvars to a unit, you need to use a timer.
If you want, I made a simmiliar system that kills a unit after it doesn't move a second, here's the code so change the actions.

JASS:
function onesecondCon takes nothing returns boolean
    return GetUnitTypeId(GetFilterUnit()) == 'h000'    
endfunction
function onesecondtimer takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit whichUnit = GetHandleUnit(t, "whichUnit")
    local real x = GetHandleReal(t, "x")
    local real y = GetHandleReal(t, "y")
    local real distance = DistanceBetweenPointsXY(x, y, GetUnitX(whichUnit), GetUnitY(whichUnit)) // this is my function that checks distance between coordinates
    if distance == 0 then
        call KillUnit(whichUnit)
    endif
    call FlushHandleLocals(t)
    call DestroyTimer(t)
    set t = null
    set whichUnit = null
endfunction
function onesecond takes nothing returns nothing
    local timer t = CreateTimer()
    local group g = CreateGroup()
    local unit whichUnit
    local real x
    local real y
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, Condition(function onesecondCon)) 
    loop
        set t = null
        set whichUnit = FirstOfGroup(g)
        exitwhen whichUnit == null
        call GroupRemoveUnit(g, whichUnit)
        set t = CreateTimer()
        call SetHandleReal(t, "x", GetUnitX(whichUnit))
        call SetHandleReal(t, "y", GetUnitY(whichUnit))
        call SetHandleHandle(t, "whichUnit", whichUnit)
        call TimerStart(t, 1, false, function onesecondtimer)
    endloop
    call DestroyGroup(g)
    set g = null
    set whichUnit = null 
endfunction

//==== Init Trigger NewTrigger ====
function InitTrig_NewTrigger takes nothing returns nothing
    set gg_trg_NewTrigger = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic( gg_trg_NewTrigger, 0.20 )
    call TriggerAddAction(gg_trg_NewTrigger, function onesecond)
endfunction
 
Level 8
Joined
Mar 23, 2007
Messages
302
ok damn YES it works.
Used your example of the Timer thing and now it works.
Thats the code i remade.
JASS:
//-----------------------------------------------------------------------

function DistanceBetweenPointsXY takes real x, real y, real x2, real y2 returns real
return  SquareRoot((x2-x)*(x2-x)+(y2-y)*(y2-y))
endfunction

               
function onesecondtimer takes nothing returns nothing  
local timer t = GetExpiredTimer()  
local unit whichUnit = GetHandleUnit(t, "whichUnit")
local real Way  
local real x = GetHandleReal(t, "x")  
local real y = GetHandleReal(t, "y")  
local real distance = DistanceBetweenPointsXY(x, y, GetUnitX(whichUnit), GetUnitY(whichUnit))// this is my function that checks distance between coordinates  
if distance != 0 then
set Way = GetHandleReal(whichUnit,"Way")  
call SetHandleReal(whichUnit, "Way", distance+Way)  
endif    
call DestroyTimer(t)  
set t = null  
set whichUnit = null 
endfunction 

function onesecond takes nothing returns nothing  
local timer t = CreateTimer()  
local group g = CreateGroup()  
local unit whichUnit 
local real x 
local real y 
call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)  
loop  
set t = null  
set whichUnit = FirstOfGroup(g)  
exitwhen whichUnit == null  
call GroupRemoveUnit(g, whichUnit)  
set t = CreateTimer()  
call SetHandleReal(t, "x", GetUnitX(whichUnit))  
call SetHandleReal(t, "y", GetUnitY(whichUnit))  
call SetHandleHandle(t, "whichUnit", whichUnit)  
call TimerStart(t, 1, false, function onesecondtimer)  
endloop  
call DestroyGroup(g)  
set g = null  
set whichUnit = null 
endfunction 

//==== Init Trigger NewTrigger ==== 
function InitTrig_MovedWay takes nothing returns nothing  
set gg_trg_MovedWay = CreateTrigger()  
call TriggerRegisterTimerEventPeriodic( gg_trg_MovedWay, 1.0 )  
call TriggerAddAction(gg_trg_MovedWay, function onesecond) 
endfunction

And i CAN attach information to units ;) .

THX for the big help.
 
Status
Not open for further replies.
Top