• 🏆 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!

[vJASS] Why my script not working?

Status
Not open for further replies.
Level 10
Joined
Jun 17, 2014
Messages
236
hello, hive.
i here want to ask why my script not working, i've try to search the problem, and i change the script that i think is wrong, and when i test it the script still not working, after repeat it about 10 times, i give up because i'm new on vJass.
and i've try to debug the script and only work on :
roar.onInit method and roar.con method, the onCast is not working.

the script is not error when i compile it, just not working.

JASS:
library garspell1
  globals
  private constant integer SPELL_ID = 'AHds' //INSERT SPELL ID
  private constant real DURATION = 15.
  private unit caster
  private constant string soundname = "war3mapImported\blablacapskjdiuoqwehsa7fbgt76awetr"
  private constant real DAMAGE = 1234
  private constant real ANIM_DUR = 1.2
  private constant integer AB_ID1 = 'ANpi'
  private constant integer AB_ID2 = 'Avul'
  private constant integer AB_ID3 = 'Apiv'
  endglobals
  struct roar
  static method con takes nothing returns boolean
  call BJDebugMsg("con")
  return GetSpellAbilityId( ) == SPELL_ID
  endmethod
static method cam takes nothing returns nothing
  call CameraSetEQNoiseForPlayer( GetEnumPlayer( ), 3 )
  call PolledWait( ANIM_DUR )
  call CameraClearNoiseForPlayer( GetEnumPlayer( ) )
  endmethod
  static method onCastd takes nothing returns nothing
  local timer casttime = CreateTimer()
  local real x = GetUnitX( caster )
  local real y = GetUnitY( caster )
  local sound cc
  local group kz
  local unit p
  local player enemy = GetOwningPlayer( caster )
  call BJDebugMsg("onCast")
  set caster = GetTriggerUnit( )
  // IF UNIT LESS THAT CRITICAL
  if GetUnitLifePercent( caster ) <= 50 then
  //PLAY CAM
  call ForForce( GetPlayersAll( ), function thistype.cam )
  //PICK UNIT
  call GroupEnumUnitsInRange( kz, x, y, 1600., null )
  loop
  set p = FirstOfGroup( kz )
  exitwhen p == null
  if IsUnitEnemy( p, enemy ) and GetUnitState( p, UNIT_STATE_LIFE ) >= 0 then
  call UnitDamageTarget( caster, p, DAMAGE, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
  //SLOW TARGET HERE
  endif
  endloop
  //PLAY A SOUND
  set cc = CreateSound( soundname, false, false, true, 12700, 12700, "" )
  call StartSound( cc )
  call KillSoundWhenDone( cc )
  //END OF PLAY A SOUND
  //PAUSE AND PLAY ANIM
  call PauseUnit( caster, true )
  call SetUnitAnimation( caster, "some animation" )
  call SetUnitAnimationByIndex( caster, /* some integer anim */ 1 )
  call PauseUnit( caster, false )
  call PauseUnit( caster, true )
  call TimerStart( casttime, ANIM_DUR, false, function thistype.onCast2 )
  else
  set cc = CreateSound( soundname, false, false, true, 12700, 12700, "" )
  call StartSound( cc )
  call KillSoundWhenDone( cc )
  //END OF PLAY A SOUND
  //PAUSE AND PLAY ANIM
  call PauseUnit( caster, true )
  call SetUnitAnimation( caster, "some animation" )
  call SetUnitAnimationByIndex( caster, /* some integer anim */ 1 )
  call PauseUnit( caster, false )
  call PauseUnit( caster, true )
  call DestroyGroup(kz)
  call TimerStart( casttime, ANIM_DUR, false, function thistype.onCast2 )
  endif
  endmethod
  static method onCast2 takes nothing returns nothing
  local timer dur = CreateTimer()
  call BJDebugMsg("onCast2")
  call PauseUnit( caster, false )
  call UnitAddAbility( caster, AB_ID1 )
  call UnitAddAbility( caster, AB_ID2 )
  call UnitAddAbility( caster, AB_ID3 )
  if GetUnitLifePercent( caster ) >= 50. then
  call SetUnitAbilityLevel( caster, AB_ID1, 1 )
  call SetUnitAbilityLevel( caster, AB_ID2, 1 )
  call SetUnitAbilityLevel( caster, AB_ID3, 1 )
  else
  call SetUnitAbilityLevel( caster, AB_ID1, 2 )
  call SetUnitAbilityLevel( caster, AB_ID2, 2 )
  call SetUnitAbilityLevel( caster, AB_ID3, 2 )
  endif
  call TimerStart( dur, DURATION, false, function thistype.onExpire )
  endmethod
  static method onExpire takes nothing returns nothing
  call UnitRemoveAbility( caster, AB_ID1 )
  call UnitRemoveAbility( caster, AB_ID2 )
  call UnitRemoveAbility( caster, AB_ID3 )
  endmethod
  static method onInit takes nothing returns nothing
  local trigger t = CreateTrigger( )
  local integer i = 0
  call BJDebugMsg("OnInit")

  loop
  exitwhen i > 15
  call TriggerRegisterPlayerUnitEvent( t, Player( i ), EVENT_PLAYER_UNIT_SPELL_EFFECT, null )
  call BJDebugMsg(I2S(i))

  set i = i + 1
  endloop
  call TriggerAddCondition( t, function thistype.con )
  call TriggerAddAction( t, function thistype.onCastd )
  endmethod
  endstruct
endlibrary
 
Level 11
Joined
Dec 19, 2012
Messages
411
In your onCastd method :

1.
JASS:
 local timer casttime = CreateTimer()
 local real x = GetUnitX( caster )
 local real y = GetUnitY( caster )
 local sound cc
 local group kz
 local unit p
 local player enemy = GetOwningPlayer( caster )
 call BJDebugMsg("onCast")
 set caster = GetTriggerUnit( )
You not even set "caster" pointer when you defining x, y and enemy.

2
local group kz
You're not even create a group for the local variable to refer to.

3.
JASS:
 loop
 set p = FirstOfGroup( kz )
 exitwhen p == null
 if IsUnitEnemy( p, enemy ) and GetUnitState( p, UNIT_STATE_LIFE ) >= 0 then
 call UnitDamageTarget( caster, p, DAMAGE, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, WEAPON_TYPE_WHOKNOWS )
 //SLOW TARGET HERE
 endif
 endloop
Your loop doesn't have GroupRemoveUnit, so the loop will run infinitely until the thread crash.



The other problems :

1. Your trigger leaks timer, and local variables should be nulled after used.
2. Your trigger can be optimized more.
3. Avoids using bj functions as usually they are inefficient (not all)
4. Your trigger is pretty hard to read...
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Your loop doesn't have GroupRemoveUnit, so the loop will run infinitely until the thread crash.
This. The thread most definitely crashes there. You will also want to set caster to the triggering unit, as DD_Legion also stated.

Also, you can combine static method con and onCastd like so:

JASS:
static method con takes nothing returns boolean

    if GetSpellAbilityId() == SPELL_ID then
        // do onCastd stuff
    endif

    return false
endmethod

Your trigger is pretty hard to read...
It might be he either typed it out manually, or he is using Firefox. Most likely the latter. If so, use the regular text editor to paste code / triggers and not the rich text editor. You will see the option on the top right of the message box (it looks like a piece of paper with a wrench).
 
Status
Not open for further replies.
Top