Game Development Community

Conversation manager

by Jonathan Lindsay · in Torque Game Builder · 11/05/2006 (8:08 pm) · 1 replies

Hi All,

I wonder if you could help me out. I'm trying to make an array that controls the order in which the player can speak to NPC's. Currently, each NPC has a mounted trigger called conversationTrigger, which works like this:

(in conversationTrigger.cs)
function ConversationTrigger::onEnter( %this, %object )
{
   if( %object.class $= "Player" )
   {
      %object.conversationSet.add( %this );
   }
}

function ConversationTrigger::onLeave( %this, %object )
{
   if( %object.class $= "Player" )
   {
      %object.conversationSet.remove( %this );
   }
}

Each instance of the mounted conversationTrigger in the TBG editor has a dynamic field added with character as the field name and 'Dan' (or whatever, depending on which NPC the trigger is mounted). Once in an NPC trigger area, the player can press the T key to evoke the startConversation function and the Q key to evoke the end conversation function.

(in player.cs)
function Player::onSpawn( %this, %pos )
{
   $Player = %this;

   %this.conversationSet = new SimSet();
     
}


function Player::startConversation( %this )
{
   if( %this.conversationSet.getCount() > 0 )
   {
      %this.isTalking = true;
      echo("start conversation with " @ %this.conversationSet.getObject(0).character);
   }
}

function Player::updateConversation( %this )
{
   echo("update conversation with " @ %this.conversationSet.getObject(0).character);
}

function Player::endConversation( %this )
{
   if (%this.isTalking)
   {
      echo("end conversation with " @ %this.conversationSet.getObject(0).character);
      %this.isTalking = false;
   }
}

After reading Paul Scotts blog (http://www.garagegames.com/blogs/10513/5705) post, i've added this below the conversationTrigger onLeave code:

function dialogue() {

    %wrapper = new ScriptObject();
    

    for(%i = 0; %i < 7; %i++) {
        %wrapper.Dan[%i] = new ScriptObject();
        %wrapper.Pilk[%i] = new ScriptObject();
        %wrapper.Psy[%i] = new ScriptObject();
        etc, etc
    }


    %wrapper.count = 7;

    bar(%wrapper);

    return %array;

}

function bar(%array) {

    %array.dump();

    for(%i = 0; %i < %array.count; %i++) {
        %obj = %array.contents[%i];
        if( isObject(%obj)) {
	    %obj.dump();
        }
        else {
          warn("You probably dont want to mix objects and values in the same array!");
	    echo("The value of array.contents[%i] is " @ %obj);
        }
    }
}

function arrayDemo() {

    %wrapper = dialogue();

    %wrapper.delete();
}

So, i want to set up an array that controls the order in which the player can talk to NPC's. Then, i'm gonna try to make an addtional multi-dimensional array which will hold the actual dialogue. Then, i'm gonna try and display the relevant string in a speech bubble mounted on each NPC.

Something like this:-
Dan Pilk Jed Fiz Psy Oran Arm
0 Blah,Blah go away go away go away go away go away go away
speak to Pilk

1 go away Blah, Blah go away go away go away go away go away
speak to Fi

2 go away go away go away Blah, Blah go away go away go away
speak to Arm

I'm sure you get the idea.

I would be very grateful if anyone could please tell me if what i want to do is possible or not, or whether i'm going in the correct direction or not. I'm totally stumped by the arrays. I'm dealing with strings and not objects so i don't think i can use simsets. I'm very new to programming in general, so please bare that in mind when replying :(

Thanks,

Jonathan

#1
04/22/2009 (1:41 am)
id do it a different way but then my code isn't always great


varibles: value1 = 0, value2 =0

JILL:
if value1 = 0
go talk to jack
set a variable and hold a value in value2 eg 1
else value = 2
thanks for my dog back :D

Jack

else value2 = 0
would you take this to jill its her dog she lost it
value1 = 2
jill

kinda makes sense in my head