• 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.

struct + Condition(function this.func) = error

Status
Not open for further replies.
Level 2
Joined
Aug 4, 2011
Messages
12
JASS:
call TriggerAddCondition(this.eventTrigger, Condition(function this.IsObjectTarget))
Causes an error: "this is not an struct name"
If i'll write
JASS:
call TriggerAddCondition(this.eventTrigger, Condition(this.IsObjectTarget))
Causes an error: "undeclared variable Quest", Quest is my struct name.
and the error sends to this line:
JASS:
call TriggerAddCondition(s__Quest_eventTrigger[this] , Condition(Quest.getMethod(IsObjectTarget,this)))

So how can i do what i want? If u r don't understand what i want look:
JASS:
///////QUEST SYSTEM///////////////////////////////////
struct Quest
   integer EVENT_KILL = 1 //on kill
   integer EVENT_SPEAK = 2//speak with npc
   integer EVENT_PICK = 3//pick an item
   
   integer rewardXP = 0//xp to heroes
   integer rewardGold = 0//gold to players
   boolean repeatable = false//can bestarted again
   integer eventType = 0//what must hero do
   trigger eventTrigger = CreateTrigger()
   unitevent eventEvent//event for trigger
   widget eventTarget//item/unit/etc
   
   method IsObjectTarget takes widget u returns boolean
      if(u == this.eventTarget) then
         return true
      endif
      return false
   endmethod
   
   method IsObjectTargetAndOrderAttack takes widget u, integer order returns boolean
      if(this.IsObjectTarget(u) == false) then
         return false
      elseif(order == OrderId("attack")) then
         return true
      else
         return false
      endif   
   endmethod
   
   method GetEvent takes nothing returns nothing
      if(this.eventType == 1) then
         set this.eventEvent = EVENT_UNIT_DEATH
         call TriggerAddCondition(this.eventTrigger, Condition(this.IsObjectTarget))
      elseif(this.eventType == 2) then
         set this.eventEvent = EVENT_UNIT_ISSUED_TARGET_ORDER
         call TriggerAddCondition(this.eventTrigger, Condition(this.IsObjectTargetAndOrderAttack))
      elseif(this.eventType == 3) then
         set this.eventEvent = EVENT_UNIT_ISSUED_TARGET_ORDER
         call TriggerAddCondition(this.eventTrigger, Condition(this.IsObjectTarget))
      endif
      
   endmethod
   
   method Create takes nothing returns nothing
      if(this.eventType == 0) then
         BJDebugMsg("Event error: eventType == 0")
         return
      endif
      call this.GetEvent()
      call TriggerRegisterUnitEvent(eventTrigger, eventTarget, eventEvent)
   endmethod
   
   method Destroy takes nothing returns nothing
      set this.eventEvent = null
      set this.eventTarget = null
      call DestroyTrigger(this.eventTrigger)
      set this.eventTrigger = null
   endmethod
endstruct
It's not finished, but i can't make it work anyway.

-hexing
 
Level 2
Joined
Aug 4, 2011
Messages
12
oh... fully bad realization, i remade all the struct, but saying "function this.func" throws an error. Why?
 
I'm vJassing yet but should method IsObjectTarget look like:
JASS:
   method IsObjectTarget takes widget u returns boolean
      return u == this.eventTarget
   endmethod
And IsObjectTargetAndOrderAttack:
JASS:
   method IsObjectTargetAndOrderAttack takes widget u, integer order returns boolean
      return this.IsObjectTarget(u) and order == OrderId("attack") 
   endmethod
Thats just for simplicity, although if i'm wrong appologize.
 
Level 2
Joined
Aug 4, 2011
Messages
12
Thanks, but how to create trigger in a struct???
I tried:
JASS:
struct Quest
   trigger eventTrigger = CreateTrigger()
   integer unitType = 0
   integer howMany = 0
   
   method KillActions takes nothing returns nothing
      
   endmethod
   
   method CreateKillQuest takes integer unitType, integer howMany returns nothing
      set this.unitType = unitType
      set this.howMany = howMany
      call TriggerRegisterPlayerUnitEvent(this.eventTrigger, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH, null) 
      //call TriggerAddAction(this.eventTrigger, function this.KillActions)
      call this.AddAction(this.eventTrigger, this.KillActions)
   endmethod
   
   method AddAction takes trigger toWho, code fromWhat returns nothing
      call TriggerAddAction( toWho, function fromWhat)
   endmethod
   
   method Destroy takes nothing returns nothing
      call DestroyTrigger(this.eventTrigger)
      set this.eventTrigger = null
   endmethod
endstruct

But it says "undeclared variable Quest" :pshock:
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Callback functions must not take parameters. Use the event responses/global transfer. So they have to be static, normally you can call a static function via a struct instance too but JassHelper does not seem to recognize/allow it for code parameters and it is not required anyway, just use function thistype.<funcName>.
 
Level 2
Joined
Aug 4, 2011
Messages
12
Callback functions must not take parameters. Use the event responses/global transfer. So they have to be static, normally you can call a static function via a struct instance too but JassHelper does not seem to recognize/allow it for code parameters and it is not required anyway, just use function thistype.<funcName>.
Thanks very much! it works! :goblin_yeah: +rep
 
Status
Not open for further replies.
Top