Easier way to use global functions?

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
lowena
Posts: 5
Joined: Fri Oct 17, 2014 9:24 pm
Location: Near Seattle, WA

Easier way to use global functions?

Post by lowena » Fri Oct 17, 2014 9:42 pm

I am making a dungeon that includes the following script:

Code: Select all

function giveskill()

for i=1, 4, 1 do
cclass = party.party:getChampion(i):getClass()

	if (cclass == "wizard") then
		party.party:getChampion(i):addSkillPoints(25)
	end

end
end
Is there an easier way to do the line "party.party:getChampion(i):addSkillPoints(25)" ? Preferably I'd rather not have to do party.party:getChampion() every time. I think I could make a variable and add that part to it, but I'd rather use a way that would do something like keep the current Champion in focus, i.e.:

Code: Select all

party.party:getChampion(1)
addSkillPoints(20)
Or something like that. :)

User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Easier way to use global functions?

Post by SnowyOwl47 » Sat Oct 18, 2014 6:50 am

lowena wrote:I am making a dungeon that includes the following script:

Code: Select all

function giveskill()

for i=1, 4, 1 do
cclass = party.party:getChampion(i):getClass()

	if (cclass == "wizard") then
		party.party:getChampion(i):addSkillPoints(25)
	end

end
end
Is there an easier way to do the line "party.party:getChampion(i):addSkillPoints(25)" ? Preferably I'd rather not have to do party.party:getChampion() every time. I think I could make a variable and add that part to it, but I'd rather use a way that would do something like keep the current Champion in focus, i.e.:

Code: Select all

party.party:getChampion(1)
addSkillPoints(20)
Or something like that. :)
One easy way i'd think to do this is make an Script_Entity and keep it as embedded, and just call it partyDo and add a simple function such as

Code: Select all

function party()
   return function()
      party.party() 
   end
end
Now Since I'm still new to lua that might work and it might not you may have to do this

Make a Script_Entity and keep it as embedded and call it partChamp or something
and and do the following

Code: Select all

function champ(i)
   return function()
      party.party:getChapion(i)() 
   end
end
That might work but have fun trying them out :D

User avatar
lowena
Posts: 5
Joined: Fri Oct 17, 2014 9:24 pm
Location: Near Seattle, WA

Re: Easier way to use global functions?

Post by lowena » Sat Oct 18, 2014 8:09 am

Well, that might work, but I think that's even clunkier than typing the full line each time. :lol: I was hoping for something like "using namespace std;" in C++ or whatever, but it's not that big of a deal.

User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Easier way to use global functions?

Post by SnowyOwl47 » Sat Oct 18, 2014 8:18 am

lowena wrote:Well, that might work, but I think that's even clunkier than typing the full line each time. :lol: I was hoping for something like "using namespace std;" in C++ or whatever, but it's not that big of a deal.
Lol well the reason why I told you that was because you can add your own things to do even more complicated things so you can turn spawning entities into simpler things or other stuff the examples i gave I know arnt, really gonna help you much :D

Post Reply