Page 1 of 1

How to pull from lists in Usecode C?

Posted: Wed Aug 15, 2018 11:34 am
by agentorangeguy
Ok I've run into a bit of a snag on Beh Lem's usecode.

In the original, apparently if your party is full of 8 people and you agree to put Beh Lem in your party, one of the non permanent members of the party interjects and says they'll return to the surface to tell everyone of your progress, giving room for Beh Lem to join. I think specifically the code i looked at from U6edit says the # 6 party member but I think just a random non permanent party member will suffice (anyone but Shamino, Iolo, Dupre).

So I figured I needed to

- pull a list of these "non-permanent members" from the party list
- randomly interject one of them to volunteer to leave from this new list

How would I go about doing this? I'm assuming its possible to pull a value from the party list with UI_get_party_list by using indexes like [5], [6], [7]?

Re: How to pull from lists in Usecode C?

Posted: Wed Aug 15, 2018 5:37 pm
by marzo
Lets say that you have a list with the numbers of the temporary NPCs in a variable called tempNPCs. You might create a function that gets the list and returns a random temporary NPC that looks like this:

Code: Select all

var getRandomTemporaryPartyNPC(var tempNPCs) {
	// Create an array with all temporary NPCs currently in the party.
	// It starts empty.
	var tempInParty = [];
	// For each NPC in the party...
	for (npc in UI_get_party_list()) {
		// ... if the NPC is in the list of temporary NPCs...
		var num = npc->get_npc_number();
		if (num in tempNPCs) {
			// ... then add it to the temporary array.
			tempInParty << num;
		}
	}
	// Get a random index in the temporary array.
	var random_index = UI_get_random(UI_get_array_size(tempInParty)) - 1;
	// Return the selected temporary NPC.
	return tempInParty[random_index];
}
Then call it to get one such NPC. I think the above should work, but I am a bit rusty in usecode syntax and I haven't tested it.

Re: How to pull from lists in Usecode C?

Posted: Thu Aug 16, 2018 10:51 am
by agentorangeguy
Cool thanks! I've only used that kind of thing with python and am a bit rusty on it, but I'll try it out and see if it works!