| 09-15-2009, 11:15 PM | #1 |
So, I came back to WC3 recently and I wanted to do some map editing. I decided to learn JASS (and, by derivative vJASS) so, in order to learn it i'm duplicating one of my old maps in vJASS rather than GUI. I started with the income system. I have a suspicion i'm simply going about this entirely the wrong way, so i'd like to ask you explain what I did wrong if you see any obvious problems. My objective was, in other vJASS blocks to be able to do something like RaiseIncome(playerid, amount) so I thought a library was the appropriate type. Last note, I realize I don't need the time variable, but I intend to have a countdown on a multiboard (along with other information) later, and I think having two timers would be inefficient. Thanks in advance. Code:
library IncomeManager initializer IM_Init
private struct playerIncome extends array
public integer bonus
public integer income
endstruct
globals
public playerIncome pi[11]
public integer time = 30
endglobals
function RoundIncome takes nothing returns nothing
local integer loopid
local integer addvalue
set time = time - 1
if time < 1 then
set loopid = 0
loop
exitwhen loopid > 11
set addvalue = pi[loopid].bonus
set addvalue = addvalue + pi[loopid].income
set pi[loopid].bonus = 0
call SetPlayerState(Player(loopid), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(loopid), PLAYER_STATE_RESOURCE_GOLD) + addvalue)
set loopid = loopid + 1
endloop
set time = 30
endif
endfunction
function IM_Init takes nothing returns nothing
local trigger incometimer = CreateTrigger()
call TriggerRegisterTimerEventPeriodic( incometimer, 1 )
call TriggerAddAction( incometimer, function RoundIncome )
set pi = playerIncome.create()
endfunction
endlibrary |
| 09-16-2009, 01:26 AM | #2 |
That isn't how array structs work: JASS:library IncomeManager initializer IM_Init private struct playerIncome extends array public integer bonus public integer income endstruct globals public integer time = 30 endglobals function RoundIncome takes nothing returns nothing local integer loopid local integer addvalue set time = time - 1 if time < 1 then set loopid = 0 loop exitwhen loopid > 11 set addvalue = playerIncome[loopid].bonus set addvalue = addvalue + pi[loopid].income set playerIncome[loopid].bonus = 0 call SetPlayerState(Player(loopid), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(Player(loopid), PLAYER_STATE_RESOURCE_GOLD) + addvalue) set loopid = loopid + 1 endloop set time = 30 endif endfunction function IM_Init takes nothing returns nothing local trigger incometimer = CreateTrigger() call TriggerRegisterTimerEventPeriodic( incometimer, 1 ) call TriggerAddAction( incometimer, function RoundIncome ) endfunction endlibrary ( array struct is like normal struct but [] casting instead of () ) |
