Page 1 of 1
Exp Problem
Posted: Sat Mar 14, 2015 6:36 am
by Eleven Warrior
Hi all. I have this problem when I give the party exp the hudPrint prints (Gained 150 Xp) 4 times, I only want it to print once. Thxs for any help on this
Code: Select all
function Stat1exp()
for i = 1, 4, 1 do
party.party:getChampion(i):gainExp(150)
hudPrint("Gained 150 Xp.")
end
end
Re: Exp Problem
Posted: Sat Mar 14, 2015 6:39 am
by Azel
Code: Select all
function Stat1exp()
for i = 1, 4, 1 do
party.party:getChampion(i):gainExp(150)
end
hudPrint("Gained 150 Xp.")
end
tada!

Re: Exp Problem
Posted: Sat Mar 14, 2015 6:44 am
by Eleven Warrior
Hi thxs man appreciated

Re: Exp Problem
Posted: Sat Mar 14, 2015 3:22 pm
by Duncan1246
Azel wrote:Code: Select all
function Stat1exp()
for i = 1, 4, 1 do
party.party:getChampion(i):gainExp(150)
end
hudPrint("Gained 150 Xp.")
end
tada!

A silly ask, I suppose, but why "for i = 1, 4, 1 do" and not simply "for i=1,4 do"??
Re: Exp Problem
Posted: Sat Mar 14, 2015 4:47 pm
by Azel
That last "1" is just the step increment. In this case we could have left it out and the loop would default to incrementing by 1, so you're right about not really needing it here. I left it in the example so that I wasn't changing too much from the original code.

Re: Exp Problem
Posted: Sat Mar 14, 2015 11:38 pm
by Duncan1246
Azel wrote:That last "1" is just the step increment. In this case we could have left it out and the loop would default to incrementing by 1, so you're right about not really needing it here. I left it in the example so that I wasn't changing too much from the original code.

OK I see, thanks
Re: Exp Problem
Posted: Mon Mar 16, 2015 6:23 am
by Eleven Warrior
Hi thxs. Yeah I was wondering about that extra "1" myself, although I don't understand what you mean by a step count

Re: Exp Problem
Posted: Mon Mar 16, 2015 8:10 am
by Azel
Looking at your Code, the value "i" starts off as 1 and then steps (increments) by 1 so it becomes 2, and then again it steps by 1 to become 3, and finally it steps by 1 a final time to become 4.
Example:
Code: Select all
for counter = 1,4,1 do
print(counter);
end
That will Print the following values: 1,2,3,4
Another way that we could write this and get the same result is:
Code: Select all
local counter = 1
while counter <= 4 do
print(counter)
counter = counter + 1;
end
This will also print the values: 1,2,3,4. The " + 1 " is the Step increment, and we can make that any number we choose.
So now try this:
Code: Select all
for counter = 1,4,2 do
print(counter);
end
That will Print the following values: 1,3
Next:
Code: Select all
for counter = 1,4,3 do
print(counter);
end
That will Print: 1,4
And lastly:
Code: Select all
for counter = 1,4,4 do
print(counter);
end
That will simply Print the value: 1