- Joined
- Aug 7, 2013
- Messages
- 1,342
Hi,
I am using WC3's
Each shell is a struct which consists of two members: a Table (Bribe's) and a TableArray (also Bribe's). The Table holds the buttons, their names, and a counter for each, while the TableArray is a 2-D mapping between these and the many different dialogs a shell may have.
Now this system works, but the code is ugly as sin! For example, here is the code for parsing the button command. It works fine, but it's impossible to read unless you've been starting at it for more than a few minutes.
I'd like a way to make it more readable and easier on the eyes, since I'll be making well over a hundred such shells by the time I am done.
I am using WC3's
dialog
type as a primitive shell for the player to perform commands or interact with the environment. Each button is thus an option or shell command. Each shell is a struct which consists of two members: a Table (Bribe's) and a TableArray (also Bribe's). The Table holds the buttons, their names, and a counter for each, while the TableArray is a 2-D mapping between these and the many different dialogs a shell may have.
Now this system works, but the code is ugly as sin! For example, here is the code for parsing the button command. It works fine, but it's impossible to read unless you've been starting at it for more than a few minutes.
I'd like a way to make it more readable and easier on the eyes, since I'll be making well over a hundred such shells by the time I am done.
JASS:
private function introMain takes nothing returns boolean
local button b = GetClickedButton()
local player p = GetTriggerPlayer()
local integer pid = GetPlayerId(p)
local trigger t
local ItemGroup backpack = playerDatum[pid].backpack
local ItemGroup bank = playerDatum[pid].bank
local NPC npc = playerDatum[pid].npcs[Bank.index]
if b == npc.twoD[INTRO * MAX_BTTNS].button[TAKE_BTTN] then
call bank.displayGroup(IDIALOG_TAKE_MSG)
set t = CreateTrigger()
call TriggerRegisterDialogEvent(t, bank.iDialog)
call TriggerAddCondition(t, Condition(function takeItem))
set playerDatum[pid].npcTrig = t
elseif b == npc.twoD[INTRO * MAX_BTTNS].button[PUT_BTTN] then
if bank.size == bank.maxSize then //the bank is full, player cannot store more items there
call DisplayTimedTextToPlayer(Player(pid), 0, 0, DSPLY_TXT_DUR, BANK_HEADER + " Your vault is full with " + I2S(bank.size) + " items.")
else //the player's party has at least 2 monsters, so we need to list his party monsters
call backpack.displayGroup(IDIALOG_PUT_MSG)
set t = CreateTrigger()
call TriggerRegisterDialogEvent(t, backpack.iDialog)
call TriggerAddCondition(t, Condition(function putItem))
set playerDatum[pid].npcTrig = t
endif
elseif b == npc.twoD[INTRO * MAX_BTTNS].button[REMOVE_BTTN] then
call bank.displayGroup(IDIALOG_REMOVE_MSG)
set t = CreateTrigger()
call TriggerRegisterDialogEvent(t, bank.iDialog)
call TriggerAddCondition(t, Condition(function removeItem))
set playerDatum[pid].npcTrig = t
elseif b == npc.twoD[INTRO * MAX_BTTNS].button[TAKE_GOLD_BTTN] then
if playerDatum[pid].npcs[Bank.index].gold == 0 then //no gold inside the bank
call DisplayTimedTextToPlayer(Player(pid), 0, 0, DSPLY_TXT_DUR, ERR_TAKE)
else
call DialogSetMessage(npc.oneD.dialog[GOLD_DIALOG], "Withdraw how much?\nAvailable: " + I2S(npc.gold))
call DialogDisplay(p, npc.oneD.dialog[GOLD_DIALOG], true)
set t = CreateTrigger()
call TriggerRegisterDialogEvent(t, npc.oneD.dialog[GOLD_DIALOG])
call TriggerAddCondition(t, Condition(function takeGold))
endif
elseif b == npc.twoD[INTRO * MAX_BTTNS].button[PUT_GOLD_BTTN] then
if GetPlayerState(Player(pid), PLAYER_STATE_RESOURCE_GOLD) == 0 then //no gold inside the bank
call DisplayTimedTextToPlayer(Player(pid), 0, 0, DSPLY_TXT_DUR, ERR_PUT)
else
call DialogSetMessage(npc.oneD.dialog[GOLD_DIALOG], "Deposit how much?\nAvailable: " + I2S(npc.gold))
call DialogDisplay(p, npc.oneD.dialog[GOLD_DIALOG], true)
set t = CreateTrigger()
call TriggerRegisterDialogEvent(t, npc.oneD.dialog[GOLD_DIALOG])
call TriggerAddCondition(t, Condition(function putGold))
endif
endif
set b = null
set t = null
return false
endfunction