Exp Problem

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Exp Problem

Post 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
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Exp Problem

Post 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! :mrgreen:
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Exp Problem

Post by Eleven Warrior »

Hi thxs man appreciated :)
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Exp Problem

Post 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! :mrgreen:
A silly ask, I suppose, but why "for i = 1, 4, 1 do" and not simply "for i=1,4 do"??
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Exp Problem

Post 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. :mrgreen:
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Exp Problem

Post 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. :mrgreen:
OK I see, thanks
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Exp Problem

Post 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 :)
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Exp Problem

Post 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
Post Reply