• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] learning vjass problem...

Status
Not open for further replies.
Level 9
Joined
Aug 21, 2008
Messages
533
i begunn learning vjass some time ago and i just dont get this running proerply...
JASS:
struct UnitExplode
real d
real r
real x
real y
unit u
unit u2 //killing unit
method UnitDead takes nothing returns nothing
    local group g
    set .x=GetUnitX(.u)
    set .y=GetUnitY(.u)
    call GroupEnumUnitsInRange(g,.x,.y,.r,null)
    loop 
    set .u = FirstOfGroup(g)
        exitwhen .u == null
        call UnitDamageTarget(.u2,.u,.d,true,false,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
    endloop
    call DestroyGroup(g)
endmethod
endstruct

function Explode takes nothing returns nothing
    local unit u= GetTriggerUnit()
    local unit u2= GetKillingUnit()
    local UnitExplode ue = UnitExplode.create() 
    set ue.u=u
    set ue.u2=u2
    set ue.r=300
    set ue.d=500
    call ue.UnitDead()
    call ue.destroy()
endfunction

//===========================================================================
function InitTrig_Explodespell takes nothing returns nothing
    local integer index
    set gg_trg_Explodespell = CreateTrigger(  )
    set index = 0
    loop
        call TriggerRegisterPlayerUnitEvent(gg_trg_Explodespell, Player(index),  EVENT_PLAYER_UNIT_DEATH, null)
        set index = index + 1
        exitwhen index == bj_MAX_PLAYER_SLOTS
    endloop
    call TriggerAddAction( gg_trg_Explodespell, function Explode)
endfunction

This i made just learning and it should damage all nearby unit nearby a diyng unit...
 
Level 11
Joined
Apr 29, 2007
Messages
826
You forget to remove the unit 'u' from the group 'g' (causing an inifite loop), in the loop inside your struct.
Beside that, you should start using better variable names. Your code is hard to understand with 1-letter things. (Alough it's not that hard with this short code, but the longer it gets the more unreadable it will get)
 
Level 9
Joined
Aug 21, 2008
Messages
533
... i should stop mapping so late at night:cute:
Thanks guys
The code is such small that there wasnt a need of better names.. and im not very creative in finding names

The reason wy i made this struct is to learn the OOP Syntax and to have something where i can give the game a radius and a damage to damage units in an area-thats all

edit:still not working....
 
Status
Not open for further replies.
Top