- Joined
- Jun 30, 2006
- Messages
- 230
Okay, I think I understand the basic concept of structs. In my last ability I made, Blur, I used HandleVars to simple store a unit so I could adjust its vertex color. I tried to understand structs earlier, but my knowledge of JASS was simply not enough.
Anyways, I can easily store a unit in a struct and call it up in my refresh function. The problem is, it's only for 1 unit. It's no better than a single-global. I don't really get methods in structs. I understand them for PHP, but my mind must not be thinking correctly or they don't work the same... I'm obviously going to need a few globals.
Here's what I have so you can see what's kind of going on:
Could someone please give a simple example of a way to store a unit using structs every time someone learns a specific ability, then call each unit in another function and do something with it? My "do something" is only setting a vertex color, so it doesn't need to be elaborate. I can do the work for my own spell myself, I just need to understand this concept better. All the tutorials I've seen do somewhat complicated things with each unit. I think I'm getting lost in what they are doing rather than concentrating on the concept. So if someone could give a simple example, that would be great.
Your help would be greatly appreciated!
Anyways, I can easily store a unit in a struct and call it up in my refresh function. The problem is, it's only for 1 unit. It's no better than a single-global. I don't really get methods in structs. I understand them for PHP, but my mind must not be thinking correctly or they don't work the same... I'm obviously going to need a few globals.
JASS:
struct BlurData
unit u
boolean wantDestroy = false
endstruct
globals
integer array Blur //this is simply to store a few constant integers for the spell, it has nothing to do with the structs part.
BlurData array BlurData_Ar
integer BlurData_total = 0
endglobals
JASS:
function Refresh takes nothing returns nothing
local unit u=BlurData.u //need to call up the unit, I realize this is not how you do it, it is just a placeholder.
local integer i=0
local integer int
loop
exitwhen i==BlurData_total
set dat= BlurData_Ar[i]
if (dat.wantDestroy) then
set BlurData_Ar[i]= BlurData_Ar[ BlurData_total - 1]
set BlurData_total=BlurData_total-1
call dat.destroy()
set i=i-1
else
set int=GetUnitAbilityLevel(u,Blur[0])
if(GetUnitState(u,UNIT_STATE_LIFE)>1)then
call SetUnitVertexColor(u,255,255,255,Blur[int])
endif
endif
set i=i+1
endloop
if (BlurData_total==0) then
// this is from the tut I read. In the end I want all units to use the same timer, but that's details for now.
call PauseTimer(Blur_timer)
endif
endfunction
function Conditions takes nothing returns boolean
set Blur[0] = 'A001'
set Blur[1] = 60
set Blur[2] = 40
set Blur[3] = 20
set Blur[4] = 2
return GetLearnedSkill()==Blur[0] and IsUnitIllusion(GetTriggerUnit())==false
endfunction
function Actions takes nothing returns nothing
local integer i=GetUnitAbilityLevel(GetTriggerUnit(),Blur[0])
local trigger t
local unit lu=GetTriggerUnit()
local BlurData u = BlurData.create()
if(i==1.0)then
call SetUnitVertexColor(lu,255,255,255,Blur[i])
set t=CreateTrigger()
call TriggerAddAction(t,function Refresh)
call TriggerRegisterTimerEventPeriodic(t,2)
set u.u=lu
else
call SetUnitVertexColor(lu,255,255,255,Blur[i])
endif
endfunction
function InitTrig_Blur takes nothing returns nothing
set gg_trg_Blur=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(gg_trg_Blur,EVENT_PLAYER_HERO_SKILL)
call TriggerAddCondition(gg_trg_Blur,Condition(function Conditions))
call TriggerAddAction(gg_trg_Blur,function Actions)
endfunction
Could someone please give a simple example of a way to store a unit using structs every time someone learns a specific ability, then call each unit in another function and do something with it? My "do something" is only setting a vertex color, so it doesn't need to be elaborate. I can do the work for my own spell myself, I just need to understand this concept better. All the tutorials I've seen do somewhat complicated things with each unit. I think I'm getting lost in what they are doing rather than concentrating on the concept. So if someone could give a simple example, that would be great.
Your help would be greatly appreciated!
Last edited: