Longtime reader, first time poster. Be gentle, we're poppin' a cherry here.
I'm working on this Footman War map that's simply... well, ambitious. The new version is practically done - except it's laggy as all hell because the triggers are all GUI. I figured it was about damn time I made the switch to JASS, and as much of a pain as it would be to go through all of my triggers, it would be worth it. Anyhow, on to the problem.
I've got this item recipe system. I'm sure it's a relatively familiar thing, being a popular feature. The gist of the system is simple; Any time a player attempts to buy a "recipe" (a dummy item that is auto-used like a tome), a trigger for each recipe is thrown that sets:
RecipeChef, which is the Hero trying to make a recipe.
RecipeIngredients [X], where X is the ingredient number. This allows for up to 6 ingredients, not that I'd need it.
RecipeResult, which is the Item result.
The item is instantly burned and then the "core trigger" is thrown.
Anyhow, I converted the trigger to JASS and did my best to optimize it. I used to know basic programming but I'm rusty. Anyhow, here's the trigger.
Here's the errors I get:
- Not recognizing the local RecipeChecker. Any line with RecipeChecker in it prompts a "WTF?" from the compiler.
- Countless "endif missing" messages.
Is it obvious or is more data needed?
Furthermore, can any advice be offered about optimizing triggers from yucky WE-generated code to cleaner JASS, and general speed tips?
I'm working on this Footman War map that's simply... well, ambitious. The new version is practically done - except it's laggy as all hell because the triggers are all GUI. I figured it was about damn time I made the switch to JASS, and as much of a pain as it would be to go through all of my triggers, it would be worth it. Anyhow, on to the problem.
I've got this item recipe system. I'm sure it's a relatively familiar thing, being a popular feature. The gist of the system is simple; Any time a player attempts to buy a "recipe" (a dummy item that is auto-used like a tome), a trigger for each recipe is thrown that sets:
RecipeChef, which is the Hero trying to make a recipe.
RecipeIngredients [X], where X is the ingredient number. This allows for up to 6 ingredients, not that I'd need it.
RecipeResult, which is the Item result.
The item is instantly burned and then the "core trigger" is thrown.
Anyhow, I converted the trigger to JASS and did my best to optimize it. I used to know basic programming but I'm rusty. Anyhow, here's the trigger.
Code:
//===========================================================================
// Trigger
//===========================================================================
function Trig_Recipe_Core_Actions takes nothing returns nothing
// LOCAL VARIABLES
local integer RecipeChecker = 1
local player RecipePlayer = GetOwningPlayer(udg_RecipeChef)
// SETUP
// RecipePlayer is used to avoid looping over players later
set RecipePlayer= GetOwningPlayer(udg_RecipeChef)
// Sets the name of the item and value of ingredients without a workaround or creating items
set udg_RecipeName = GetItemName(udg_RecipeResult)
// Sets the color of the item name based on level
if ( GetItemLevel(GetLastCreatedItem()) == 2 ) then
set udg_RecipeCost = 1500
set udg_RecipeName = ( "|c000042ff" + ( udg_RecipeName + "|r" ) )
endif
if ( GetItemLevel(GetLastCreatedItem()) == 3 ) then
set udg_RecipeCost = 3000
set udg_RecipeName = ( "|c00540081" + ( udg_RecipeName + "|r" ) )
endif
// Checks for items
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 6
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
if ( ( UnitHasItemOfTypeBJ(udg_RecipeChef, udg_RecipeIngredients[GetForLoopIndexA()]) == false ) and ( udg_RecipeIngredients[GetForLoopIndexA()] != 'I04A' ) ) then
// This makes a comma seperated list
if ( RecipeChecker == 1 ) then
set RecipeChecker = 0
else
set udg_RecipeMessage = ( udg_RecipeMessage + ", " )
endif
// Tell the player what item(s) he or she is missing... without a workaround
set udg_RecipeMessage = ( udg_RecipeMessage + GetItemName(udg_RecipeIngredients[GetForLoopIndexA()]) )
else
endif
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
// WORKUP
if ( RecipeChecker == 1 ) then
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 6
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
if ( udg_RecipeIngredients[GetForLoopIndexA()] != 'I04A' ) then
call RemoveItem( GetItemOfTypeFromUnitBJ(udg_RecipeChef, udg_RecipeIngredients[GetForLoopIndexA()]) )
else
endif
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
call CreateItemLoc( udg_RecipeResult, GetUnitLoc(udg_RecipeChef) )
call UnitAddItemSwapped( GetLastCreatedItem(), udg_RecipeChef )
set udg_RecipeMessage = ( ( GetHeroProperName(udg_RecipeChef) + " now carries the " ) + ( udg_RecipeName + "!" ) )
else
call AdjustPlayerStateBJ( udg_RecipeCost, GetOwningPlayer(udg_RecipeChef), PLAYER_STATE_RESOURCE_GOLD )
call DisplayTimedTextToForce( GetForceOfPlayer(udg_RecipePlayer), 10.00, ( udg_RecipeName + " requires more items for creation:" ) )
set udg_RecipeMessage = ( "|c7f7f7f00" + ( udg_RecipeMessage + "|r" ) )
endif
call DisplayTimedTextToForce( GetForceOfPlayer(udg_RecipePlayer), 10.00, udg_RecipeMessage )
// CLEANUP
set udg_RecipeCost = 0
set udg_RecipeMessage = ""
set udg_RecipeName = ""
set udg_RecipeChef = null
set bj_forLoopAIndex = 1
set bj_forLoopAIndexEnd = 6
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
set udg_RecipeIngredients[GetForLoopIndexA()] = 'I04A'
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
endfunction
//===========================================================================
// Initial Declaration
//===========================================================================
function InitTrig_Recipe_Core takes nothing returns nothing
set gg_trg_Recipe_Core = CreateTrigger( )
call TriggerAddAction( gg_trg_Recipe_Core, function Trig_Recipe_Core_Actions )
endfunction
Here's the errors I get:
- Not recognizing the local RecipeChecker. Any line with RecipeChecker in it prompts a "WTF?" from the compiler.
- Countless "endif missing" messages.
Is it obvious or is more data needed?
Furthermore, can any advice be offered about optimizing triggers from yucky WE-generated code to cleaner JASS, and general speed tips?