04 Aug, 2011, arholly wrote in the 1st comment:
Votes: 0
Hello:
I'm not sure I'm understanding why I am being told something is uninitialized. I am being told "warning: 'vch' is used uninitialized in this function", but I don't understand why it is saying that. Could someone explain it to me?

Thanks.
void spell_ventriloquate( int sn, int level, CHAR_DATA *ch,void *vo,int target)
{
char buf1[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
char speaker[MAX_INPUT_LENGTH];
CHAR_DATA *vch;

target_name = one_argument( target_name, speaker );

/* old code */
/* sprintf( buf1, "%s says '%s'.\n\r", speaker, target_name );
sprintf( buf2, "Someone makes %s say '%s'.\n\r", speaker, target_name );
*/
/* New code to fix bug in spell.*/
sprintf(buf1, "%s says '%s'.\n\r",
IS_NPC(vch) ? vch->short_descr : vch->name, target_name);
sprintf(buf2, "Someone makes %s say '%s'.\n\r",
IS_NPC(vch) ? vch->short_descr : vch->name, target_name);

buf1[0] = UPPER(buf1[0]);

for ( vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room )
{
if (!is_exact_name( speaker, vch->name) && IS_AWAKE(vch))
send_to_char( saves_spell(level,vch,DAM_OTHER) ? buf2 : buf1, vch );
}

return;
}
04 Aug, 2011, Zeno wrote in the 2nd comment:
Votes: 0
vch is never set to anything by the time the code gets to the sprintf section.
04 Aug, 2011, Vatiken wrote in the 3rd comment:
Votes: 0
vch is defined in the for() and as such any prior calls to it will be produce valid warnings for being uninitialized.

From the looks of your code, your 'new code' should be inserted before send_to_char() in the for() loop. Just make sure to use your { and } .
04 Aug, 2011, Kaz wrote in the 4th comment:
Votes: 0
arholly said:
Hello:
I'm not sure I'm understanding why I am being told something is uninitialized. I am being told "warning: 'vch' is used uninitialized in this function", but I don't understand why it is saying that. Could someone explain it to me?


It's because vch is used uninitialised in your function.

Quote
void spell_ventriloquate( int sn, int level, CHAR_DATA *ch,void *vo,int target)
{
char buf1[MAX_STRING_LENGTH];
char buf2[MAX_STRING_LENGTH];
char speaker[MAX_INPUT_LENGTH];

// DECLARATION HERE!
CHAR_DATA *vch;

target_name = one_argument( target_name, speaker );

/* old code */
/* sprintf( buf1, "%s says '%s'.\n\r", speaker, target_name );
sprintf( buf2, "Someone makes %s say '%s'.\n\r", speaker, target_name );
*/
/* New code to fix bug in spell.*/

// FIRST USE IS HERE
sprintf(buf1, "%s says '%s'.\n\r",
IS_NPC(vch) ? vch->short_descr : vch->name, target_name);



What is vch on its first use? Anything it wants to be.
04 Aug, 2011, David Haley wrote in the 5th comment:
Votes: 0
Echo Echo Echo.


Sometimes I wonder how this code ever made it into a release. Did they not run the function even once? Did they bother compiling the code?

The mysteries of life.
04 Aug, 2011, Kaz wrote in the 6th comment:
Votes: 0
I always found Diku-related code to be a frequent source of surprises.
04 Aug, 2011, Rarva.Riendf wrote in the 7th comment:
Votes: 0
David Haley said:
Echo Echo Echo.


Sometimes I wonder how this code ever made it into a release. Did they not run the function even once? Did they bother compiling the code?

The mysteries of life.


Not only that but even what it does is not what you expect it would do: Do not fire mprog like if the player actually did say it, and the messages are wrong as if the player is invis for the one who hear it, he stills see the name instead of 'someone'

My own method to create sound, and I am not even sure I thought of everything:



void spell_ventriloquate(int sn, int level, CHAR_DATA *ch, void *vo, int target) {
do_createSound(level, ch, vo);
}

bool_t do_createSound(int level, CHAR_DATA *ch, void *vo) {
if ( !vo) {
send_to_char("You cannot ventriloquate silence, unfortunately indeed.\n\r", ch);
return FALSE;
}
char speaker[MAX_INPUT_LENGTH];
vo = one_argument(vo, speaker);
CHAR_DATA *victim = get_char_room(ch, speaker);
if ( !victim) {
send_to_char("No one around by this name.\n\r", ch);
return FALSE;
}
if (victim == ch) {
send_to_char("Maybe you should just SAY it….\n\r", ch);
return FALSE;
}
char text[MAX_INPUT_LENGTH];
one_argument(vo, text);
if (text[0] == '\0') {
act("Make $m say what ?", ch, victim, NULL, TO_CHAR);
return FALSE;
}
char spellText[MAX_INPUT_LENGTH];
sprintf(spellText, "%s", drunk_text(capitalize(text), ch)); //if you are drunk don't expect to sound sober

short int nbCharsToFool = 0;
CHAR_DATA *vch;
for (vch = ch->in_room->people;vch;vch = vch->next_in_room) {
if (vch == ch || !vch->valid || (IS_AFFECTED(vch,AFF_CHARM) && vch->master == ch))
continue;//your charmies wont say anything but your group member are not devoted to you
nbCharsToFool ++;
}
CHAR_DATA *trigger_char[nbCharsToFool];
short int i = 0;
for (i = 0;i < nbCharsToFool;i ++)
trigger_char[i] = NULL;
i = 0;

char success[MAX_STRING_LENGTH];
char halfFail[MAX_STRING_LENGTH];
char totalFail[MAX_STRING_LENGTH];
short int nbCharsThatSpottedIt = 0;
for (vch = ch->in_room->people;vch;vch = vch->next_in_room) {
if (vch == ch || vch == victim || !vch->valid || (IS_AFFECTED(vch,AFF_CHARM) && vch->master == ch))
continue;
sprintf(success, "%s says '%s'.\n\r", capitalize(PERS(victim, vch)), spellText);
sprintf(halfFail, "Someone makes %s say '%s'.\n\r", PERS(victim, vch), spellText);
sprintf(totalFail, "%s makes %s say '%s'.\n\r", capitalize(PERS(ch, vch)), PERS(victim, vch), spellText);

bool_t failedToFool = saves_spell(level * (IS_AFFECTED(vch, AFF_BLIND) ? 3 : 1.5), vch, DAM_MENTAL);
if (failedToFool && (can_see(vch, ch) || can_see(vch, victim)))
nbCharsThatSpottedIt ++;
send_to_char(COLOR(vch, SAY_COLOR), vch);
send_to_char(!failedToFool ? success : can_see(vch, ch) ? totalFail : can_see(vch, victim) ? halfFail : success, vch);
send_to_char(COLOR(vch, NORMAL_COLOR), vch);
if ( !failedToFool && IS_NPC (vch) && (vch->pIndexData->progtypes & SPEECH_PROG) && nbCharsThatSpottedIt == 0) {
trigger_char[i] = vch;
i ++;
}
}
//specific to victim and char
sprintf(success, "You say '%s'.\n\r", spellText);
sprintf(halfFail, "Someone made you say '%s'.\n\r", spellText);
sprintf(totalFail, "%s made you say '%s'.\n\r", capitalize(PERS(ch, victim)), spellText);
bool_t failedToFool = saves_spell(level * (IS_AFFECTED(victim, AFF_BLIND) ? 3 : 1.5), victim, DAM_MENTAL);
if (failedToFool && can_see(victim, ch))
nbCharsThatSpottedIt ++;
send_to_char(failedToFool ? (can_see(victim, ch) ? totalFail : halfFail) : success, victim);
if (nbCharsThatSpottedIt == nbCharsToFool) //everyone spotted you without a doubt
do_say(ch, spellText);
else if (nbCharsThatSpottedIt == 0)
send_to_char("You fooled everyone.\n\r", ch);
else
send_to_char("Seems like you did not fool everyone.\n\r", ch);

//triggers launch: we do it there as otherwise can die, be transfered elsewhere etc
for (i=0; i< nbCharsToFool; i++) {
if (trigger_char[i] && trigger_char[i]->valid && trigger_char[i]->in_room == victim->in_room)
mprog_wordlist_check(spellText, trigger_char[i], victim, NULL, NULL, SPEECH_PROG);
}
return TRUE;
}

bool_t do_ventriloquate(CHAR_DATA *ch, char *argument) {
if (!argument || argument[0] == '\0'){
send_to_char("You cannot ventriloquate silence, unfortunately indeed.\n\r", ch);
return FALSE;
}

int sn = skill_lookup("ventriloquate");
int chance = get_skill(ch,sn);
if (chance == 0) {
send_to_char("You consider starting a one man show and start carving a wood puppet.\n\r", ch);
return FALSE;
}
do_wait( ch, skill_table[sn].beats );
if (number_percent() > chance) {
do_say(ch, argument);
interpret(ch, "innocent", FALSE);
check_improve(ch, sn, FALSE, 2);
return FALSE;
}
do_createSound(ch->level, ch, argument);
check_improve(ch, sn, TRUE, 2);
return TRUE;
}


The spell is only a call cause I also use the method for a skill
0.0/7