Page 1 of 1

Need help with ordinals.

Posted: Sat May 11, 2013 9:10 pm
by Ryeath_Greystalk
I may be in deep trouble here.

I'm ready to test my mod up to, but not including the boss fight, and I just now discovered that if I move my characters around then then the incorrect characters will speak.
I thought that once a character was assigned a number it never changes. From the modding page

Champion:getOrdinal()
Returns champion’s ordinal index between 1 and 4. The ordinal index is an unique identifier for the champion. It is guaranteed that the ordinal index never changes after character creation.

Apparently that is not the same as

party:getChampion(x):getName()

How do I make it so when the characters are moved around they keep the same number?

Thanks.

Re: Need help with ordinals.

Posted: Sun May 12, 2013 12:38 am
by JohnWordsworth
So, the ordinal is kind of like an ID I guess, which you have to get by querying a champion in a 'party slot'. If I were you, I would probably do the following;

1. Define a function 'someScript.getChampionWithOrdinal()', off the top of my head, it would look something like this...

Code: Select all

function getChampionWithOrdinal(ordinal)
  for i=1,4 do
    if ( party:getChampion(i):getOrdinal() == ordinal ) 
      return party:getChampion(i);
    end
  end

  return nil;
end
2. Then update your code anywhere you are doing speech from party:getChampion(x):getName() to someScript.getChampionWithOrdinal(x):getName(). You might just be able to do a find/replace across your code with the new method, but backup everything before hand!

Re: Need help with ordinals.

Posted: Sun May 12, 2013 1:42 am
by Ryeath_Greystalk
Thanks JohnWordsworth.

I thought the variable refered to the ordinal, but as you point out it's the party slot.

At least that gives me something to work with.

Re: Need help with ordinals.

Posted: Sun May 12, 2013 7:44 am
by Ryeath_Greystalk
Was not to difficult so far,

Code: Select all

-- Ordinal Test Champion 1

function championOneName()

	local name1
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 1 then
			name1 = party:getChampion(x):getName()
			break
		end
	end
	
	return name1
		
end

-- Ordinal Test Champion 2

function championTwoName()

	local name2
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 2 then
			name2 = party:getChampion(x):getName()
			break
		end
	end
	
	return name2
		
end

-- Ordinal Test Champion 3

function championThreeName()

	local name3
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 3 then
			name3 = party:getChampion(x):getName()
			break
		end
	end
	
	return name3
		
end

-- Ordinal Test Champion 4

function championFourName()

	local name4
	
	for x = 1,4 do
		if party:getChampion(x):getOrdinal() == 4 then
			name4 = party:getChampion(x):getName()
			break
		end
	end
	
	return name4
		
end
Then I just replace :party:getChampion():etName()nwith

local name1 = name_check.championOneName(name1) etc. etc.

Also have to do a little bit more because of my system of rendering the player unconcious instead of dying and reviving them if they have to speak.

Code: Select all

for y = 1,4 do
			if party:getChampion(y):getOrdinal() == 1 then
				if party:getChampion(y):getEnabled() == false then
					party:getChampion(y):setStat("health",5)
					--revive1_1:deactivate()
					party:getChampion(y):setEnabled(true)
				end
				break
			end
		end
I already have the set enabled code, just have to nest it nside the ordinal check iterator.

Thanks for the advice Mr Wordsworth.