The Dink Network

Alternate conversations

February 16th 2007, 06:20 AM
dragon.gif
I want to make it so that a lot of NPC's sometimes say 2 different things, and don't say the same thing twice in a row. I've been trying to make it so that it uses a local variable. So far, however, I have had no luck, and I've tried rearranging stuff as much and as many times as I can think of.
So is this possible with local variables, and if so, am I using them wrong, or is it certain things in the wrong place or order. So far what I have is:

void main(void)
{
int &convo = 1;

}

void talk(void)
{

if (&convo == 1);
{
freeze(1);

//conversation

&convo += 1;

unfreeze(1);
}

else

if (&convo == 2);
{
freeze(1);

//conversation 2

unfreeze(1);
}
}
Most of the times after I've rearranged the if, else, and variable assignment positions, both conversations just run together as one (like what happens in the example above.) There was only one time I got it to just go through the first conversation only, but the next time I talked to the NPC, they still had the 1st conversation only. (I've rearranged them too many times to remember exactly how I had it that time)

So am I doing it wrong, or is it just not possible to do with a local variable? I'm tired of messing with it for now and searching through other sources for examples, heheh.

Thanks
February 16th 2007, 06:46 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
An "else" needs braces around it too.

if (&foo == &bar)
{
//blah
}
else
{
if (&foo == &baz)
{
//other blah
}
}

If you reverse the order of your ifs, you can do without the elses completely:

if (&convo == 3)
{
//blah
&convo += 1;
}

if (&convo == 2)
{
//blah
&convo += 1;
}

Another alternative:

if (&convo == 1)
{
//blah
&convo +=1;
//use return if there is nothing more to be done in the talk procedure.
return;
//use goto if you need to continue.
goto convdone;
}

if (&convo == 2)
{
//blah
&convo += 1;
//either return; or goto convdone;
goto convdone;
}

convdone:
//blah!

The local variable will reset once you leave the screen, though. If that's not a problem, this will do. If you want him to remember what he said last even after screenchange, ask again. Globals can do, but there's a better trick to be used, and this post is getting too long to explain it.
February 16th 2007, 07:14 AM
dragon.gif
Thanks a bunch.

I can actually think of a few examples right now where that will come in handy in the future.. But there's no need to answer that right away.. I've got a lot more to do still before I'll need to use something like that, and a reference for when I would want to use it will definitely come in handy.

Thanks again.