[RPG] Removing a character from a party

Let's make some video games!

Moderator: Ice Cream Jonsey

Post Reply
User avatar
Ice Cream Jonsey
Posts: 25262
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

[RPG] Removing a character from a party

Post 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.
the dark and gritty...Ice Cream Jonsey!

User avatar
Ice Cream Jonsey
Posts: 25262
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: [RPG] Removing a character from a party

Post by Ice Cream Jonsey »

I think I have it.
the dark and gritty...Ice Cream Jonsey!

User avatar
Flack
Posts: 7870
Joined: Tue Nov 18, 2008 3:02 pm
Location: Oklahoma
Contact:

Re: [RPG] Removing a character from a party

Post 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?
"Jack Flack always escapes." -Davey Osborne

User avatar
The Happiness Engine
Posts: 868
Joined: Thu Aug 02, 2012 4:16 pm

Re: [RPG] Removing a character from a party

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

User avatar
Tdarcos
Posts: 7654
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Re: [RPG] Removing a character from a party

Post 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.
"Perhaps she'll understand, if you tell it to her, plain."
- Don McLean, Castles in the Air

User avatar
Ice Cream Jonsey
Posts: 25262
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Re: [RPG] Removing a character from a party

Post by Ice Cream Jonsey »

I think it works. Onto burst mode for automatic weapons!
the dark and gritty...Ice Cream Jonsey!

Post Reply