11 Nov, 2016, Merryweather wrote in the 1st comment:
Votes: 0
I've been toying around with a SWRFOTE codebase for awhile now in my spare time, and I really kinda love it. Unfortunately, however, what I know how to do with code is a result of exploring codebases over the years, then piecing bits together until it does what I want it to. I am not good at this by any means. I'm hoping somebody (an actual coder) might be able to take one look at this and pinpoint what I'm doing wrong.

The idea is to have a "voice" command that allows the user to select a vocal tone from a predesignated list. This is heavily inspired by LOTJ's tone system, which I've always adorned.

To start, here is my voice.c file:

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "mud.h"

char * const voice_names[] = {
"none", "squeaky", "angry", "unknown"

int const voice_array[] = {

void do_voice( CHAR_DATA *ch, char *argument )
int voices;

argument = one_argument(argument, arg );

for ( voices = 0; voice_array[voices] != VOICE_UNKNOWN; voices++ )
if ( !str_prefix( arg, voice_names[voices] ) )
ch->vocalizing = voice_array[voices];
set_char_color( AT_SAY, ch );
ch_printf( ch, "You now sound %s.\n\r", voice_names[voices] );
set_char_color( AT_SAY, ch );
send_to_char( "That is not a tone of voice you can use.\n\r", ch );

As far as I can tell in testing, voice.c seems to be working fine. I can set a voice in-game, I can change it, and entering "voice fduhsfd" tells you it's not a valid voice.

Where I run into trouble is when trying to use voice in channels or the say command. For example, this is the chat channel, with ch->vocalizing added in to it:


ch_printf( vch, "Public Comm [Freq: %s]: (%d) %s%s%s%s %s\n\r", ch->comfreq, ch->vocalizing, color_str(AT_CHAT, vch),
IS_IMMORTAL(vch) ? " &R(&W" : "",
IS_IMMORTAL(vch) ? ch->name : "",
IS_IMMORTAL(vch) ? "&R)&W" : "", argument );

Compiles fine, all good. Except, it prints as a number in-game:

Public Comm [Freq: 467.689]: (2) Lala

I've tried changing the %d to %s, thinking it would print the string instead of the integer, and while it compiles clean, the game immediately crashes (segfault) when I test using the channel with a voice set.

What I am attempting to accomplish is having the voice display in the parenthesis, not the number. Where am I going wrong?
11 Nov, 2016, Merryweather wrote in the 2nd comment:
Votes: 0
In case it helps, from mud.h:

extern	int	const	voice_array      [];
extern char * const voice_names [];

#define VOICE_NONE       BV00
#define VOICE_ANGRY BV02
11 Nov, 2016, Pymeus wrote in the 3rd comment:
Votes: 0
ch->vocalizing looks like it must be an integer type, but you want to print a string. So first you need to use %s, and then you need to provide it with a string instead of a number. You could keep a pointer to the voice_names[] string directly in the 'ch' structure, or provide a means to look up the string based on the value of ch->vocalizing in the voice_names[] array.

I would say get rid of the bitvector (unless you have a need for a bitvector that isn't represented here) and voice_array[], and store the index of voice_names[] in ch->vocalizing directly.
12 Nov, 2016, Merryweather wrote in the 4th comment:
Votes: 0
Thank you very much!