Hey, I'm a long-time GUI coder, who fairly recently switched over to vJASS. I'm able to accomplish most things that I try to do, and I use natives and clean leaks and such.
However, what I'm curious about is why it seems all the code I see from other people on the forums and such is different than mine. A lot of people seem to use Structs as their initializers, and differences like that.
Also there is all the external libraries that people use, like TimerUtils and such, that I never really understood that well.
My question for you guys is what's wrong with my coding style, because it's different than what everyone else seems to do. I don't mean like "how exactly would you do this one part more efficiently?" but just what can you gleam as being incorrect about the whole code style / format?
Example of my coding style
However, what I'm curious about is why it seems all the code I see from other people on the forums and such is different than mine. A lot of people seem to use Structs as their initializers, and differences like that.
Also there is all the external libraries that people use, like TimerUtils and such, that I never really understood that well.
My question for you guys is what's wrong with my coding style, because it's different than what everyone else seems to do. I don't mean like "how exactly would you do this one part more efficiently?" but just what can you gleam as being incorrect about the whole code style / format?
Example of my coding style
JASS:
library Setup initializer Init
//===========================================================================
globals
unit array pl_base[8]
unit array pl_hero[8]
hashtable array pl_table[8]
endglobals
private function Start takes nothing returns nothing
local integer i = 0
local real x
local real y
local rect r = gg_rct_Center
local rect r2
loop
exitwhen i == 1
if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
if Player(i) == Player(0) then
set r2 = gg_rct_Red_Base
elseif Player(i) == Player(1) then
set r2 = gg_rct_Blue_Base
elseif Player(i) == Player(2) then
set r2 = gg_rct_Teal_Base
elseif Player(i) == Player(3) then
set r2 = gg_rct_Purple_Base
endif
set bj_lastCreatedFogModifier = CreateFogModifierRect(Player(i), FOG_OF_WAR_VISIBLE, r, true, false)
call FogModifierStart(bj_lastCreatedFogModifier)
set bj_lastCreatedUnit = CreateUnit(Player(i), 'hbse', GetStartLocationX(i), GetStartLocationY(i), 0)
set pl_base[i] = bj_lastCreatedUnit
set bj_lastCreatedUnit = CreateUnit(Player(i), 'Hmge', GetRectCenterX(r) + i * 200, GetRectCenterY(r) - 500, 90)
set pl_hero[i] = bj_lastCreatedUnit
call UnitAddAbility(bj_lastCreatedUnit, 'Abrd')
call SetUnitInvulnerable(bj_lastCreatedUnit, false)
call CreateUnit(Player(i), 'htwr', GetRectMinX(r2), GetRectMinY(r2), 0)
call CreateUnit(Player(i), 'htwr', GetRectMaxX(r2), GetRectMinY(r2), 0)
call CreateUnit(Player(i), 'htwr', GetRectMinX(r2), GetRectMaxY(r2), 0)
call CreateUnit(Player(i), 'htwr', GetRectMaxX(r2), GetRectMaxY(r2), 0)
call SetPlayerState(Player(i), PLAYER_STATE_GIVES_BOUNTY, 1)
set pl_table[i] = InitHashtable()
endif
set i = i + 1
endloop
set r = null
set r2 = null
endfunction
private function Init takes nothing returns nothing
local trigger t1 = CreateTrigger()
local trigger t2 = CreateTrigger()
local integer i = 0
call TriggerAddAction(t1, function Start)
call TriggerAddAction(t2, function Choose)
call TriggerRegisterTimerEvent(t1, 0.1, false)
loop
call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
set i = i + 1
exitwhen i == 8
endloop
endfunction
//===========================================================================
endlibrary