[JASS] Error from this code

Level 8
Joined
Dec 16, 2007
Messages
253
This is a spell I requested, but I'm getting error upon saving and I cannot test the spell.

I'm getting "Cannot convert codereturnboolean to boolexpr" error on this line:
JASS:
call TriggerAddCondition(t , function GoldGain__Condition)



JASS:
library GoldGain initializer Init uses TimerUtils
   globals
      private constant real TimeInterval = 60
      private integer array GoldPerInterval
      private constant integer AbID = 'A000' //Change this to rawcode of your Ability!
   endglobals
   struct GG
      unit u
      timer t

      static method Loop takes nothing returns nothing
         local timer t = GetExpiredTimer()
         local GG g = GetTimerData(t)
         if GetUnitAbilityLevel(g.u, AbID) != 0 then
            call SetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD) + GoldPerInterval[GetUnitAbilityLevel(g.u, AbID)])
         else
            call PauseTimer(g.t)
            call ReleaseTimer(g.t)
            call g.destroy()
         endif
         set t = null
      endmethod
      static method Start takes nothing returns nothing
         local GG g = g.allocate()
         set g.u = GetTriggerUnit()
         set g.t = NewTimer()
         call SetTimerData(g.t, g)
         call TimerStart(g.t, TimeInterval, true, function GG.Loop)
      endmethod
      method onDestroy takes nothing returns nothing
         set .u = null
         set .t = null
      endmethod
   endstruct
   private function Condition takes nothing returns boolean
      return GetSpellAbilityId() == AbID
   endfunction

   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      local player p
      local integer i = 0
      loop
         exitwhen i == bj_MAX_PLAYER_SLOTS
         set p = Player(i)
         call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_HERO_SKILL, null)
         set p = null
         set i = i + 1
      endloop
      call TriggerAddCondition(t, function Condition)
      call TriggerAddAction(t, function GG.Start)
      set GoldPerInterval[1] = 40
      set GoldPerInterval[2] = 100
      set GoldPerInterval[3] = 160
      set GoldPerInterval[4] = 220
      set t = null
   endfunction
endlibrary
 
Level 11
Joined
Apr 6, 2008
Messages
760
JASS:
   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      local integer i = 0
      loop
         exitwhen i == bj_MAX_PLAYER_SLOTS
         call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_HERO_SKILL, null)
         set i = i + 1
      endloop
      call TriggerAddCondition(t, function Condition)
      call TriggerAddAction(t, function GG.Start)
      set GoldPerInterval[1] = 40
      set GoldPerInterval[2] = 100
      set GoldPerInterval[3] = 160
      set GoldPerInterval[4] = 220
      set t = null
   endfunction

no need for the player handle
 
Level 14
Joined
Nov 18, 2007
Messages
815
JASS:
library GoldGain initializer Init uses TimerUtils, PUI

   globals
      private constant real TimeInterval = 60
      private integer array GoldPerInterval
      private constant integer AbID = 'A000' //Change this to rawcode of your Ability!
   endglobals

   //! runtextmacro PUI_PROPERTY("private", "integer", "GGLvl", "0")

   private struct GG // private because we dont want a user to use this struct
      unit u
      timer t

      static method Loop takes nothing returns nothing
         local GG g = GetTimerData(GetExpiredTimer())
         if GetUnitAbilityLevel(g.u, AbID) != 0 then
            call SetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD) + GoldPerInterval[GetUnitAbilityLevel(g.u, AbID)])
         else
            call g.destroy()
         endif
      endmethod

      static method Start takes nothing returns nothing
         local GG g
         if GGLvl[g.u]==0 then
             set g = GG.allocate()
             set g.u = GetTriggerUnit()
             set g.t = NewTimer()
             set GGLvl[g.u]=GetUnitAbilityLevel(g.u, AbID)
             call SetTimerData(g.t, g)
             call TimerStart(g.t, TimeInterval, true, function GG.Loop)
         endif
      endmethod

      method onDestroy takes nothing returns nothing
          set .u = null
          call ReleaseTimer(.t)
      endmethod
   endstruct

   private function Condition takes nothing returns boolean
      return GetSpellAbilityId() == AbID
   endfunction

   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_SKILL)
      call TriggerAddCondition(t, Condition(function Condition))
      call TriggerAddAction(t, function GG.Start)
      set GoldPerInterval[1] = 40
      set GoldPerInterval[2] = 100
      set GoldPerInterval[3] = 160
      set GoldPerInterval[4] = 220
   endfunction
endlibrary
Seriously, keep that thing in one thread, im basically quoting my response to that older thread.

Edit: Duh, found an error.
2nd Edit: Another one.
 
Last edited:
Level 8
Joined
Dec 16, 2007
Messages
253
Doesn't work. It doesn't display Test3 or 4. Not getting errors upon saving, but it refuses to work.

JASS:
library GoldGain initializer Init uses TimerUtils, PUI

   globals
      private constant real TimeInterval = 5
      private integer array GoldPerInterval
      private constant integer AbID = 'A000' //Change this to rawcode of your Ability!
   endglobals

   //! runtextmacro PUI_PROPERTY("private", "integer", "GGLvl", "0")

   private struct GG // private because we dont want a user to use this struct
      unit u
      timer t

      static method Loop takes nothing returns nothing
         local GG g = GetTimerData(GetExpiredTimer())
         call BJDebugMsg("Test4")
         if GetUnitAbilityLevel(g.u, AbID) != 0 then
            call SetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(g.u), PLAYER_STATE_RESOURCE_GOLD) + GoldPerInterval[GetUnitAbilityLevel(g.u, AbID)])
         else
            call g.destroy()
         endif
      endmethod

      static method Start takes nothing returns nothing
         local GG g
         call BJDebugMsg("Test3")
         if GGLvl[g.u]==0 then
             set g = GG.allocate()
             set g.u = GetTriggerUnit()
             set g.t = NewTimer()
             set GGLvl[g.u]=GetUnitAbilityLevel(g.u, AbID)
             call SetTimerData(g.t, g)
             call TimerStart(g.t, TimeInterval, true, function GG.Loop)
         endif
      endmethod

      method onDestroy takes nothing returns nothing
          set .u = null
          call ReleaseTimer(.t)
      endmethod
   endstruct

   private function Conditions takes nothing returns boolean
            call BJDebugMsg("Test2")
      return GetSpellAbilityId() == AbID
   endfunction

   private function Init takes nothing returns nothing
      local trigger t = CreateTrigger()
      call BJDebugMsg("Test1")
      call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_HERO_SKILL)
      call TriggerAddCondition(t, Condition(function Conditions))
      call TriggerAddAction(t, function GG.Start)
      set GoldPerInterval[1] = 40
      set GoldPerInterval[2] = 100
      set GoldPerInterval[3] = 160
      set GoldPerInterval[4] = 220
   endfunction
endlibrary
 
Top