Page 1 of 1

[RPG] Removing a character from a party

Posted: Sun May 31, 2020 10:13 pm
by Ice Cream Jonsey
Thinking out loud on a pattern.

The thing I am working on supports removing (and optionally saving to disk) a character.

If there's just one character in the party then that's easy, decrement the number of characters in the party. No characters will show up as I am using a global for the number of characters in a party.

If the sixth character is removed that is also easy. Decrement number of characters in the party, the sixth one does not show up. (I should blank out the objects and arrays that make up the definition of that character, of course.)

If there are between two and five members... I want the effect of the characters that were "later" in the party "moving up."

So after the character gets removed, if there are two or more characters or four or fewer characters, I'll do things.

Wait, no, that's wrong - the third character could be removed, which means that we have 5 characters. Still gotta move characters around.

Re: [RPG] Removing a character from a party

Posted: Sun May 31, 2020 10:23 pm
by Ice Cream Jonsey
I think I have it.

Re: [RPG] Removing a character from a party

Posted: Mon Jun 01, 2020 6:25 am
by Flack
I'm probably making this either too easy or too hard, but maybe every turn something could check for an empty character slot, and if it finds one, run through the rest of the character array and subtract one from each position?

Re: [RPG] Removing a character from a party

Posted: Mon Jun 01, 2020 2:44 pm
by The Happiness Engine
Since execution time cannot POSSIBLY matter can you just write out a new array of characters, skipping the one you are removing? For architectural limitations just have 2 arrays with one being used as a scratch space and then write the array back to where it normally lives.

Re: [RPG] Removing a character from a party

Posted: Mon Jun 01, 2020 4:48 pm
by Tdarcos
Here is a general sample where "deadman" is the particular character being deleted, "group" is the array of members, "maxmembers" is the number of characters currently in the group.

Code: Select all

for i = deadman to maxmembers
{
  group[i] = group[i+1]
  group[i+1] = nothing
}
  maxmembers = maxmembers - 1
Since I don't know what language you're using I've been generic, C/C++ has special operators such that the last line above could be

maxmembers -- ;

The small amount of time cleaning each entry after every move means the last entry is automatically cleared. Also, if you're doing this visually, each person in the party moves up and there is a vacancy after each one steps forward, before the next moves in.

Hope this helps.

Re: [RPG] Removing a character from a party

Posted: Mon Jun 08, 2020 5:17 pm
by Ice Cream Jonsey
I think it works. Onto burst mode for automatic weapons!