bkeener101
02-21-2013, 01:43 AM
I've been picking at this for hours now and I cannot seem to find where I am going wrong. Could anyone offer any insight?
Here's the code and I will explain afterwards.
if (mainBP:CountItemsOfID(manaPotionID) ~= currentManaPotions) then
if (mainBP:CountItemsOfID(manaPotionID) < currentManaPotions) then
local manaUsed = currentManaPotions - mainBP.CountItemsOfID(manaPotionID)
currentManaPotions = mainBP.CountItemsOfID(manaPotionID)
manaPotions = manaPotions + manaUsed
hudManaPotion:SetText(manaPotionName .. ": " .. manaPotions .. " (" .. manaPotions * manaPotionPrice .. ")")
end
if (mainBP:CountItemsOfID(manaPotionID) > currentManaPotions) then
currentManaPotions = mainBP.CountItemsOfID(manaPotionID)
end
end
Okay now. Assume that all variables are provided, I have thoroughly checked that.
mainBP is set as a value that the user inputs at the beginning (I have it set to 2854, a brown backpack)
manaPotionID is set in the beginning also (I have it as 268, a mana potion)
currentManaPotions is initiated as 0
manaPotions is initiated as 0
Now, given those variables, this should do the following:
Upon starting the script, it should see that I have 300 manaPotions in my mainBP. Since 300 ~= 0, and 300 > 0, it should execute the third if statement which would set currentManaPotions to 300.
After this, I use a manaPotion. Since I now have 299 in my mainBP, 299 ~= 300, and 299 < 300, so the second if statement should be executed, which should set manaUsed to 1(300-299). Then it should set currentManaPotions to 299, set manaPotions to 1, and print the new amount to the HUD.
Now here is where I'm stumped. I added in print statements in each if statement to track which statement is executed, and to print currentManaPotions to the screen. Upon executing the script, the first if statement is executed with currentManaPotions = 0, then the third if statement is executed(which should set currentManaPotions to 300) but it prints currentManaPotions = 0. Since it stays set to 0, it just goes in an infinite loop executing if statements 1 and 2, never updating.
So this is what is happening. Any ideas? x.x
Here's the code and I will explain afterwards.
if (mainBP:CountItemsOfID(manaPotionID) ~= currentManaPotions) then
if (mainBP:CountItemsOfID(manaPotionID) < currentManaPotions) then
local manaUsed = currentManaPotions - mainBP.CountItemsOfID(manaPotionID)
currentManaPotions = mainBP.CountItemsOfID(manaPotionID)
manaPotions = manaPotions + manaUsed
hudManaPotion:SetText(manaPotionName .. ": " .. manaPotions .. " (" .. manaPotions * manaPotionPrice .. ")")
end
if (mainBP:CountItemsOfID(manaPotionID) > currentManaPotions) then
currentManaPotions = mainBP.CountItemsOfID(manaPotionID)
end
end
Okay now. Assume that all variables are provided, I have thoroughly checked that.
mainBP is set as a value that the user inputs at the beginning (I have it set to 2854, a brown backpack)
manaPotionID is set in the beginning also (I have it as 268, a mana potion)
currentManaPotions is initiated as 0
manaPotions is initiated as 0
Now, given those variables, this should do the following:
Upon starting the script, it should see that I have 300 manaPotions in my mainBP. Since 300 ~= 0, and 300 > 0, it should execute the third if statement which would set currentManaPotions to 300.
After this, I use a manaPotion. Since I now have 299 in my mainBP, 299 ~= 300, and 299 < 300, so the second if statement should be executed, which should set manaUsed to 1(300-299). Then it should set currentManaPotions to 299, set manaPotions to 1, and print the new amount to the HUD.
Now here is where I'm stumped. I added in print statements in each if statement to track which statement is executed, and to print currentManaPotions to the screen. Upon executing the script, the first if statement is executed with currentManaPotions = 0, then the third if statement is executed(which should set currentManaPotions to 300) but it prints currentManaPotions = 0. Since it stays set to 0, it just goes in an infinite loop executing if statements 1 and 2, never updating.
So this is what is happening. Any ideas? x.x