I'm trying to set the Conditions to a trigger (full trigger at bottom, it is not completed). The issue is with this piece of it.
I am trying to use this section to detect when a table has ended.
if CraftingRecipes[1] is actually nil though, the trigger breaks and breaks hard. The trigger exits completely out of the while loop and never hits the next line of code or return false. Is this normal behavior? Is there an easier way to see how long a table is? (Google tells me no, Lua has no built-in ability to check the length of an array)
I wasn't planning on this table being dynamic, but I wanted to set it up in such a way that I wouldn't have to change a variable all the time to know the size of the table, or make an overly large table and go through the blank entries while processing spells that aren't on the table.
If the spell is on the table, it reaches the Actions and stops at print("Doing Actions") (haven't really crafted that yet, actions is still in puesdocode stage at this point)
Full Trigger
Code:
if CraftingRecipes[i][1] == nil then
print("Spell Cast Not Craft Spell")
return false
end
if CraftingRecipes[1] is actually nil though, the trigger breaks and breaks hard. The trigger exits completely out of the while loop and never hits the next line of code or return false. Is this normal behavior? Is there an easier way to see how long a table is? (Google tells me no, Lua has no built-in ability to check the length of an array)
I wasn't planning on this table being dynamic, but I wanted to set it up in such a way that I wouldn't have to change a variable all the time to know the size of the table, or make an overly large table and go through the blank entries while processing spells that aren't on the table.
If the spell is on the table, it reaches the Actions and stops at print("Doing Actions") (haven't really crafted that yet, actions is still in puesdocode stage at this point)
Full Trigger
Code:
function CraftItemInitalize()
local i = 0
local trigger = CreateTrigger()
local TriggerConditions = function()
print("Spell Cast!")
local i = 1
local spell = GetSpellAbilityId()
print("Spell Ability ID Get?")
print("SpellID: "..spell)
while true do
if CraftingRecipes[i][1] == nil then
print("Spell Cast Not Craft Spell")
return false
end
print(i)
if CraftingRecipes[i][1] == spell then
print("Crafting Recipe "..i.." Cast")
return true
end
i = i + 1
end
print("Something Went Wrong")
return false
end
local TriggerActions = function()
local i = 1
local unit = GetTriggerUnit()
local player = GetOwningPlayer(unit)
local recipe = {}
print("Doing Actions")
while true do
if CraftingRecipes[i][1] == nil then
print("Something Went Terribly Wrong")
recipe = CraftingRecipes[1]
break
end
if CraftingRecipes[i][1] == spell then
print("Crafting Recipe "..i.." Casting now")
recipe = CraftingRecipes[i]
break
end
i = i + 1
end
end
Last edited: