Game Development Community

Speech Blurbs/Bubbles (A.K.A. Poking the Tiger with a Stick)

by Orion the Hunter · in Torque Game Builder · 05/24/2013 (4:46 pm) · 24 replies

Hello,

So I was searching the forum for a way to make speech bubbles but I didn't manage to snag anything for TGB, at least, without being told to use GuiTextCtrls. Now, the GUI system is all well and good but I was hoping for something that doesn't stay fixed in the screen, you know? So, maybe T2D Text Objects would be a more viable a solution, preferably something without code because right now, Torque 2D 1.7.6 is on the verge of exploding (like I said in the title). And anyway, the code files we usually killed by the upgrading process... or something (not sure). *Ahem* Here is my wish-list.

-No code files (*.h, *.cc, ect...)
-Limited, if not, no GUI elements
-Flexible and painless bubbles where you can just set their text with a behavior or something

I would prefer if these were met, but it's totally fine if they can't. A resource would be awesome. Thanks!
Page «Previous 1 2
#1
05/26/2013 (8:22 am)
Here's what I have so far, but it doesn't even work...

//Blurb Behavior

//-----------------------------------------------------------------------------
//HandDrawn 1.0
// Blurbs
//-----------------------------------------------------------------------------

if ( !isObject( SpeechDisplayBehavior ) )
{
    %template = new BehaviorTemplate( SpeechDisplayBehavior );

    %template.friendlyName = "Blurb Text";
    %template.behaviorType = "Miscellaneous";
    %template.description  = "Set this behavior to something so when the player interacts with them, they engage them in a conversation.";

   %template.addBehaviorField(BlurbText, "What the person should say when they are collided with.", string, "");
    %template.addBehaviorField( PlayerOnly, "Damage the player, not other actors",       BOOL,  false );
}

function SpeechDisplayBehavior::onAddToScene( %this, %scenegraph )
{

    if ( %this.PlayerOnly )
    {
        %this.Owner.setObjectType( "PlayerTrigger" );
        %this.Owner.setCollidesWith( "PlayerObject" );
    }
    else
    {
        %this.Owner.setObjectType( "ActorTrigger" );
        %this.Owner.setCollidesWith( "ActorObject" );
    }

}

function SpeechDisplayBehavior::onCollision( %this, %theirObject, %ourRef, %theirRef, %time, %normal, %contacts, %points )
{
echo("Entered Area...");
$game::player.lastInteracted = %this.Owner;
%this.Owner.Targettext = %this.BlurbText;
SpeechFunction::BlurbSpawn();
}

//Blurb Script

//Blurb Script File
//By JackRabbit

//First, let's start with creating a speech bubble.

function SpeechFunction::onAddToScene(%this)
{
%Pos = %this.getSpeaker();
%this.speachPos.X = %pos.Position.X;
%this.speachPos.Y = %pos.Position.Y - 15;
}

function SpeechFunction::BlurbSpawn(%this)
{
echo("Created bubble");
%this.Blurb = new t2dStaticSprite()
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      imageMap = "SpeechBubbleImageMap";
      frame = "0";
      sourceRect = "0 0 0 0";
      canSaveDynamicFields = "1";
      Position = %this.SpeachPos;
      size = "50.000 20.000";
      LinkPoints = "-0.748 -0.133 -0.069 -0.899 0.047 -0.696";
         mountID = "173";
   };

%this.SpText = new t2dTextObject() 
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      canSaveDynamicFields = "1";
      Position = "17.000 6.000";
      size = "48.284 2.452";
      SortPoint = "-0.161 -0.631";
      font = "Chalkboard";
      wordWrap = "1";
      hideOverflow = "1";
      textAlign = "Left";
      lineHeight = "2.452";
      aspectRatio = "1";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "0";
      fontSizes = "84";
      textColor = "1 1 1 1";
      bilinearFilter = "0";
      snapToInteger = "0";
      noUnicode = "0";
         hideOverlap = "0";
         mountID = "174";
   };
%this.SpText.position.Y = %this.Blurb.Position.Y - 8;
%this.InitText();
}

function SpeechFunction::getSpeaker(%this)
{
%this.Speaker = $game::player.lastInteracted;
return %this.Speaker;
}

function SpeechFunction::InitText(%this)
{
%this.SpText.text = %this.Speaker.TargetText;
}
#2
05/27/2013 (8:13 am)
Ah, okay, so I combined the two script files into one behavior which seems to work. Any suggestions on how I would improve this?

//-----------------------------------------------------------------------------
//HandDrawn 1.0
// Blurbs
//-----------------------------------------------------------------------------
//Adapted From Blurb Script File
//By JackRabbit

//First, let's start with creating a speech bubble.

function SpeechDisplayBehavior::BlurbSpawn(%this)
{
echo("Created bubble");
%this.Blurb = new t2dStaticSprite(SpeechBubble)
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      imageMap = "SpeechBubbleImageMap";
      frame = "0";
      sourceRect = "0 0 0 0";
      canSaveDynamicFields = "1";
      Position = %this.speechPos;
      size = "50.000 20.000";
      LinkPoints = "-0.748 -0.133 -0.069 -0.899 0.047 -0.696";
         mountID = "173";
   };

%this.SpText = new t2dTextObject(SpeechText)
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      canSaveDynamicFields = "1";
      Position = %this.textPos;
      SortPoint = "-0.161 -0.631";
      size = "50 3.000";
      font = "Chalkboard";
      text = "Hi!";
      wordWrap = "1";
      BlendColor = "1 1 1 1";
      hideOverflow = "0";
      textAlign = "Left";
      lineHeight = "3";
      aspectRatio = "1";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "0";
      fontSizes = "84";
      textColor = "1 1 1 1";
      bilinearFilter = "0";
      snapToInteger = "0";
      noUnicode = "0";
         hideOverlap = "0";
         mountID = "174";
   };
%this.InitText();
}

function SpeechDisplayBehavior::getSpeaker(%this)
{
%this.Speaker = $game::player.lastInteracted;
return %this.Speaker;
}

function SpeechDisplayBehavior::InitText(%this)
{
%this.SpText.text = %this.blurbText;
}

function SpeechBubble::onAddToScene(%this)
{
%this.SpeechPos = %this.Speaker.position;
}

function SpeechText::onAddToScene(%this)
{
%YPOS = %this.Speaker.Position.Y - 8;
%this.TextPos = %this.Speaker.position.X SPC %YPOS;
}

if ( !isObject( SpeechDisplayBehavior ) )
{
    %template = new BehaviorTemplate( SpeechDisplayBehavior );

    %template.friendlyName = "Blurb Text";
    %template.behaviorType = "Miscellaneous";
    %template.description  = "Set this behavior to something so when the player interacts with them, they engage them in a conversation.";

   %template.addBehaviorField(BlurbText, "What the person should say when they are collided with.", string, "");
    %template.addBehaviorField( PlayerOnly, "Damage the player, not other actors",       BOOL,  false );
}

function SpeechDisplayBehavior::onAddToScene( %this, %scenegraph )
{

    if ( %this.PlayerOnly )
    {
        %this.Owner.setObjectType( "PlayerTrigger" );
        %this.Owner.setCollidesWith( "PlayerObject" );
    }
    else
    {
        %this.Owner.setObjectType( "ActorTrigger" );
        %this.Owner.setCollidesWith( "ActorObject" );
    }

}

function SpeechDisplayBehavior::onEnter( %this, %theirObject )
{
echo("Entered Area...");
%theirObject.lastInteracted = %this;
%this.Targettext = %this.BlurbText;
%this.getSpeaker();
%this.BlurbSpawn();
%this.Owner.safeDelete();
}

Yeah, it seems to work well enough. I just need some tips to make it better, such as making the text not all appear at once but come in in a typewriter motion.
#3
05/27/2013 (2:42 pm)
The "typewriter" motion could be achieved by writing a function that updates the text in the TextObject.
function typewriterText(%timer, %myMessage)
{
	%len = strlen(%myMessage);
	for (%i = 1; %i <= %len; %i++)
	{
		%tempStr = getSubStr(%myMessage, 0, %i);
		%time = %i * %timer;
		schedule(%time, 0, "updateText", %tempStr);
	}
}

function updateText(%message)
{
        // set the text of your control to the message value - this is just for demonstration.
	echo(" @@@ updating: " @ %message);
}
#4
05/29/2013 (7:41 am)
Okay, so I've done some work on the script using your suggestion. Now, nothing's showing up. I'm guessing I messed something up down on the bottom of the script... could you take a look, please?

//-----------------------------------------------------------------------------
//HandDrawn 1.0
// Blurbs
//-----------------------------------------------------------------------------
//Adapted From Blurb Script File
//By JackRabbit

//First, let's start with creating a speech bubble.

function SpeechDisplayBehavior::BlurbSpawn(%this)
{
echo("Created bubble");
%this.Blurb = new t2dStaticSprite(SpeechBubble)
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      imageMap = "SpeechBubbleImageMap";
      frame = "0";
      sourceRect = "0 0 0 0";
      canSaveDynamicFields = "1";
      Position = %this.speechPos;
      size = "50.000 20.000";
      LinkPoints = "-0.748 -0.133 -0.069 -0.899 0.047 -0.696";
         mountID = "173";
   };

%this.SpText = new t2dTextObject(SpeechText)
   {
        SceneGraph    = Scenewindow2D.getSceneGraph();
      canSaveDynamicFields = "1";
      Position = %this.textPos;
      SortPoint = "-0.161 -0.631";
      size = "50 3.000";
      font = "Chalkboard";
      text = "Hi!";
      wordWrap = "1";
      BlendColor = "1 1 1 1";
      hideOverflow = "0";
      textAlign = "Left";
      lineHeight = "3";
      aspectRatio = "1";
      lineSpacing = "0";
      characterSpacing = "0";
      autoSize = "0";
      fontSizes = "84";
      textColor = "1 1 1 1";
      bilinearFilter = "0";
      snapToInteger = "0";
      noUnicode = "0";
         hideOverlap = "0";
         mountID = "174";
   };
%this.InitText();
}

function SpeechDisplayBehavior::getSpeaker(%this)
{
%this.Speaker = $game::player.lastInteracted;
return %this.Speaker;
}

function SpeechDisplayBehavior::InitText(%this)
{
%this.SpText.text = %this.Targettext;
}

function SpeechBubble::onAddToScene(%this)
{
%this.SpeechPos = %this.Speaker.position.X SPC %this.Speaker.position.Y - 8;
}

function SpeechText::onAddToScene(%this)
{
%YPOS = %this.Speaker.Position.Y - 8;
%this.TextPos = %this.Speaker.position.X SPC %YPOS;
}

if ( !isObject( SpeechDisplayBehavior ) )
{
    %template = new BehaviorTemplate( SpeechDisplayBehavior );

    %template.friendlyName = "Blurb Text";
    %template.behaviorType = "Miscellaneous";
    %template.description  = "Set this behavior to something so when the player interacts with them, they engage them in a conversation.";

   %template.addBehaviorField(BlurbText, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(timer, "What the person should say when they are collided with.", float, "1000");
    %template.addBehaviorField( PlayerOnly, "Damage the player, not other actors",       BOOL,  false );
}

function SpeechDisplayBehavior::onAddToScene( %this, %scenegraph )
{

 //   if ( %this.PlayerOnly )
   // {
  //      %this.Owner.setObjectType( "PlayerTrigger" );
        %this.Owner.setCollidesWith( "PlayerObject" );
   // }
   // else
    //{
   //     %this.Owner.setObjectType( "ActorTrigger" );
    //    %this.Owner.setCollidesWith( "ActorObject" );
  //  }

}

function SpeechDisplayBehavior::onEnter( %this, %theirObject )
{
echo("Entered Area...");
%theirObject.lastInteracted = %this.owner;
%this.getSpeaker();
%this.typewriterText();
%this.BlurbSpawn();


    if( !$game::player.FlipX )
    {
    %this.Speaker.FlipX = 1;
    }
    else
    {
    %this.Speaker.FlipX = 0;
    }

//%this.Owner.safeDelete();

}

function SpeechDisplayBehavior::typewriterText(%this)
{
	%len = strlen(%this.BlurbText);
	for (%i = 1; %i <= %len; %i++)
	{
		%this.tempStr = getSubStr(%this.BlurbText, 0, %i);
		%this.time = %i * %this.timer;
		%this.schedule(%this.time, 0, "updateText", %this.tempStr);
	}
}

function SpeechDisplayBehavior::updateText(%this)
{
%this.Targettext = %this.tempStr;
echo(%this.TargetText);
}
#5
05/29/2013 (8:30 am)
function SpeechDisplayBehavior::BlurbSpawn(%this)  
{  
    echo("Created bubble");  
    %this.Blurb = new t2dStaticSprite()  
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        imageMap = "SpeechBubbleImageMap";  
        frame = "0";  
        sourceRect = "0 0 0 0";  
        canSaveDynamicFields = "1";  
        Position = %this.speechPos;  
        size = "50.000 20.000";  
        LinkPoints = "-0.748 -0.133 -0.069 -0.899 0.047 -0.696";  
        mountID = "173";  
    };
    %textPosX = getWord(%this.Blurb.getPosition(), 0);
    %textPosY = getWord(%this.Blurb.getPosition(), 1);
    %blurbSizeY = getWord(%this.Blurb.size, 1);
    %textPos = %textPosX + 8 SPC %textPosY + (%blurbSizeY / 2) - 12;
    %this.SpText = new t2dTextObject()  
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        canSaveDynamicFields = "1";  
        Position = %textPos;
        SortPoint = "-0.161 -0.631";  
        size = "50 3.000";  
        font = "Chalkboard";  
        text = "Hi!";  
        wordWrap = "1";  
        BlendColor = "1 1 1 1";  
        hideOverflow = "0";  
        textAlign = "Left";  
        lineHeight = "3";  
        aspectRatio = "1";  
        lineSpacing = "0";  
        characterSpacing = "0";  
        autoSize = "0";  
        fontSizes = "84";  
        textColor = "0 0 0 1";  
        bilinearFilter = "0";  
        snapToInteger = "0";  
        noUnicode = "0";  
        hideOverlap = "0";  
        mountID = "174";  
    };
    %this.InitText();  
}  
// ----
function SpeechDisplayBehavior::typewriterText(%this)  
{  
    %len = strlen(%this.BlurbText);  
    for (%i = 1; %i <= %len; %i++)  
    {  
        %tempStr = getSubStr(%this.BlurbText, 0, %i);  
        %time = %i * %this.timer;  
        %this.schedule(%time, "updateText", %tempStr);  
    }  
}  
  
function SpeechDisplayBehavior::updateText(%this, %string)  
{
    %this.SpText.text = %string;  
    echo(%this.SpText.text);  
}

You can get rid of that echo in updateText.

Note that I removed the names from the blurb and blurb text objects in BlurbSpawn. This is because all text bubbles will end up replacing each other's blurb objects if they are named - object names must be unique. Just to be clear: OBJECT NAMES MUST BE UNIQUE. Can't emphasize this enough - if you remember this it will save you tons of headaches.
#6
05/29/2013 (9:43 am)
Thanks, mate!

This works great. Many thanks for the help!
#7
05/29/2013 (10:24 am)
Oh, one other thing. How would I render multiple lines of text? For example, it says one thing, and then if you press the side arrow, it renders a new line. Thanks! :)
#8
05/29/2013 (1:32 pm)
You'd have to get the length of the string, split it into two or more parts and then make a t2dTextObject for each line. Have your input handle telling it which line to display - could set the others Visible=false.
#9
05/30/2013 (9:48 am)
Fantastic. Sorry to be so demanding, but is there a way to detect when it is done typing the text? That way, I could make it so it would render a new line of text when you press a button. I think it calls "Update Text" multiple times, and it doesn't keep calling it forever because the sound I have it play stops after rendering the last character. I've tried
if(%this.SpText.text = %this.blurbText)
{
echo("Done!");
}
But it doesn't react. Any more tips? Thanks so much, by the way.
#10
05/30/2013 (10:51 pm)
Just have it schedule a call to a "done" function after it finishes with the current line schedules - Just use the time in %this.time after the for loop in typewriterText().
#11
05/31/2013 (11:00 am)
Okay! So a little snippet of code has gone a long way... mostly thanks to you. :P I'm sure you know that coding is 99% trial and error, so it will come as no surprise to you that I have hit a road-bock. The problem is that when I press "C" after the first line renders, it renders the next line. However, it only works once and when I try to render the third line, it just gives me a blank message. Not only that, but it skips the second line and goes to the third. Any tips on how I could clean it up?

//-----------------------------------------------------------------------------
//HandDrawn 1.0
// Blurbs
//-----------------------------------------------------------------------------
//Adapted From Blurb Script File
//By JackRabbit

//First, let's start with creating a speech bubble.

if ( !isObject( SpeechDisplayBehavior ) )
{
    %template = new BehaviorTemplate( SpeechDisplayBehavior );

    %template.friendlyName = "Blurb Text";
    %template.behaviorType = "Miscellaneous";
    %template.description  = "Set this behavior to something so when the player interacts with them, they engage them in a conversation.";

   %template.addBehaviorField(BlurbText, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText2, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText3, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText4, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText5, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText6, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText7, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText8, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText9, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(BlurbText10, "What the person should say when they are collided with.", string, "");
   %template.addBehaviorField(numLines, "How many lines?", float, "1");


   %template.addBehaviorField(timer, "What the speed should be.", float, "25");
    %template.addBehaviorField( PlayerOnly, "Collide with the player, not other actors",       BOOL,  false );
    %template.addBehaviorField( isDestroyer, "Destroy a bubble, not make one.",       BOOL,  false );
   %template.addBehaviorField(targetSpeaker, "The person who's talking", object, "", t2dSceneObject);
   %template.addBehaviorField(speechDest, "The person who's talking", object, "", t2dSceneObject);

}

function SpeechDisplayBehavior::onCollision(%this, %theirobject)
{
echo("Collided with Blurb Trigger...");
%theirObject.lastInteracted = %this.owner;
%this.getSpeaker();
%this.typewriterText();
%this.BlurbSpawn();


    if( !$game::player.FlipX )
    {
    %this.TargetSpeaker.FlipX = 1;
    }
    else
    {
    %this.TargetSpeaker.FlipX = 0;
#12
05/31/2013 (11:00 am)
...And more...

if(%this.isDestroyer)
{
//Left blank for now...
}
}
}
function SpeechDisplayBehavior::BlurbSpawn(%this)  
{  
    echo("Created bubble");  
    %this.Blurb = new t2dStaticSprite()  
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        imageMap = "SpeechBubbleImageMap";  
        frame = "0";  
        sourceRect = "0 0 0 0";  
        canSaveDynamicFields = "1";  
        Position = %this.speechDest.position;  
        size = "50.000 20.000";  
        mountID = "173";
    };
    %textPosX = getWord(%this.Blurb.getPosition(), 0);
    %textPosY = getWord(%this.Blurb.getPosition(), 1);
    %blurbSizeY = getWord(%this.Blurb.size, 1);
    %textPos = %textPosX SPC %textPosY - 5;
    %this.SpText = new t2dTextObject(TextObj)
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        canSaveDynamicFields = "1";  
        Position = %textPos;
        SortPoint = "-0.161 -0.631";
        size = "48.000 3.000";  
        font = "Chalkboard";  
        text = "Hi!";  
        wordWrap = "1";  
        BlendColor = "1 1 1 1";  
        hideOverflow = "0";  
        textAlign = "Left";  
        lineHeight = "3";  
        aspectRatio = "1";  
        lineSpacing = "0";  
        characterSpacing = "0";  
        autoSize = "0";  
        fontSizes = "84";  
        textColor = "1 1 1 1";  
        bilinearFilter = "0";  
        snapToInteger = "0";  
        noUnicode = "0";  
        hideOverlap = "0";  
        mountID = "174";  
    };
    %this.InitText();  

}

function SpeechDisplayBehavior::getSpeaker(%this)
{
%this.Speaker = $game::player.lastInteracted;
return %this.Speaker;
}

function SpeechDisplayBehavior::InitText(%this)
{
%this.SpText.text = %this.Targettext;
}

function SpeechBubble::onAddToScene(%this)
{
%this.SpeechPos = SpeechDisplayBehavior.SpeechDest;
}

function SpeechText::onAddToScene(%this)
{
%YPOS = speechDisplayBehavior.Speaker.Position.Y - 8;
speechDisplayBehavior.TextPos = speechDisplayBehavior.Speaker.position.X SPC %YPOS;
}

function SpeechDisplayBehavior::onAddToScene( %this, %scenegraph )
{
%this.nextText[1] = %this.BlurbText;
%this.nextText[2] = %this.BlurbText2;
%this.nextText[3] = %this.BlurbText3;
%this.nextText[4] = %this.BlurbText4;
%this.nextText[5] = %this.BlurbText5;
%this.nextText[6] = %this.BlurbText6;
%this.nextText[7] = %this.BlurbText7;
%this.nextText[8] = %this.BlurbText8;
%this.nextText[9] = %this.BlurbText9;
%this.nextText[10] = %this.BlurbText10;

    if ( %this.PlayerOnly )
    {
        %this.Owner.setObjectType( "PlayerTrigger" );
        %this.Owner.setCollidesWith( "PlayerObject" );
    }
    else
    {
        %this.Owner.setObjectType( "ActorTrigger" );
        %this.Owner.setCollidesWith( "ActorObject" );
    }
}
#13
05/31/2013 (11:03 am)
And some more...

function SpeechDisplayBehavior::onEnter( %this, %theirObject )
{
$speechLine = 1;


$isCanceled = 0;

echo("Entered Area...");
%theirObject.lastInteracted = %this.owner;
%this.getSpeaker();
%this.typewriterText();
%this.BlurbSpawn();


    if( !$game::player.FlipX )
    {
    %this.TargetSpeaker.FlipX = 1;
    }
    else
    {
    %this.TargetSpeaker.FlipX = 0;
    }

//%this.Owner.safeDelete();

}

function SpeechDisplayBehavior::typewriterText(%this)  
{  
    %len = strlen(%this.BlurbText);
    for (%i = 1; %i <= %len; %i++)  
    {
        if(!$isCanceled)
        {
        %tempStr = getSubStr(%this.BlurbText, 0, %i);
        %time = %i * %this.timer;  
        %this.schedule(%time, "updateText", %tempStr);
        }
    }
%doneTime = %this.timer * strlen(%this.BlurbText);
%this.doneevent = %this.schedule(%Donetime, "TextDone");
$speechLine += 1;

}

$Bing[1] = "Bing1";
$Bing[2] = "Bing2";
$Bing[3] = "Bing3";
$Bing[4] = "Bing4";
$Bing[5] = "Bing5";
$Bing[6] = "Bing6";
$Bing[7] = "Bing7";

function SpeechDisplayBehavior::updateText(%this, %string)  
{
if( isObject ( %this.Blurb ) )
{
    %bingSound = $bing[getRandom(1,7)];
    %this.SpText.text = %string;
    echo(%this.SpText.text);
    playsound(talk);
}
}
function SpeechDisplayBehavior::onleave( %this, %theirObject, %string )
{
%string = "";
$speechLine = 1;
$isCanceled = 1;
%event = %this.doneEvent;
cancel(%event);
stopSound(talk);

%this.SpText.safeDelete();
%this.Blurb.safeDelete();

    if( !$game::player.FlipX )
    {
    %this.TargetSpeaker.FlipX = 1;
    }
    else
    {
    %this.TargetSpeaker.FlipX = 0;
    }
	GlobalActionMap.unbindObj(keyboard, "C");
}
#14
05/31/2013 (11:04 am)
...And the rest... (Gotta love the character limit, lol) :P

function SpeechDisplayBehavior::textDone(%this)
{
Warn("Speech done!");
if(%this.numLines >= $SpeechLine)
{
GlobalActionMap.bindObj("keyboard", "C", "nextLine", %this);
}
else
{
error("Lines are done rendering!!!" @ $speechLine @ "," @ " " @ %this.numlines);
}
}


function speechDisplayBehavior::nextLine( %this )
{
//Delete the other blurb
$SpeechLine += 1;

if(%this.numLines <= $SpeechLine && %this.numLines != 1)
{
GlobalActionMap.unbindObj(keyboard, "C");
%this.Blurb.safeDelete();
%this.SpText.safeDelete();
    %this.Blurb = new t2dStaticSprite()  
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        imageMap = "SpeechBubbleImageMap";  
        frame = "0";  
        sourceRect = "0 0 0 0";  
        canSaveDynamicFields = "1";  
        Position = %this.speechDest.position;  
        size = "50.000 20.000";  
        mountID = "173";
    };
    %textPosX = getWord(%this.Blurb.getPosition(), 0);
    %textPosY = getWord(%this.Blurb.getPosition(), 1);
    %blurbSizeY = getWord(%this.Blurb.size, 1);
    %textPos = %textPosX SPC %textPosY - 5;
    %this.SpText = new t2dTextObject(TextObj)
    {  
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        canSaveDynamicFields = "1";  
        Position = %textPos;
        SortPoint = "-0.161 -0.631";  
        size = "48.000 3.000";  
        font = "Chalkboard";  
        text = "Hi!";  
        wordWrap = "1";  
        BlendColor = "1 1 1 1";  
        hideOverflow = "0";  
        textAlign = "Left";  
        lineHeight = "3";  
        aspectRatio = "1";  
        lineSpacing = "0";  
        characterSpacing = "0";
        autoSize = "0";  
        fontSizes = "84";  
        textColor = "1 1 1 1";  
        bilinearFilter = "0";  
        snapToInteger = "0";  
        noUnicode = "0";  
        hideOverlap = "0";  
        mountID = "174";  
    };
    %this.InitText();  

%this.blurbText = %this.NextText[$speechLine];

%this.typewriterText();

}
else
{
    if($speechLine = 1)
    {
    error("First line!");
    }

}
}
#15
05/31/2013 (7:14 pm)
It sounds like you're approaching "programming" all wrong.... 99% is a LOT of trial and error.

Now, at the end of typewriterText() remove the $speechLine += 1 bit - because you then turn around and increment it again in your nextLine() method.

Next, about that nextLine() method - unless there is a very compelling reason to delete the old blurb and add a new one, it would be better to just clear the text in the t2dTextObject and reuse it.
function speechDisplayBehavior::nextLine( %this )   
{   
	//Delete the other blurb   
	$SpeechLine += 1;   

	if(%this.numLines <= $SpeechLine && %this.numLines != 1)   
	{   
		%this.blurbText = %this.NextText[$speechLine];   
		%this.SpText.text = "";
		%this.typewriterText();   
	}   
	else  
	{   
		if($speechLine = 1)   
		{   
			error("First line!");   
		}   
	}   
}

And stop using globals for all of this stuff - if you do that then when more than one thing displays a speech blurb they'll all say the same thing. You should hold this in a field on the behavior:
%this.SpeechLine = 1;

Next - these:
function SpeechBubble::onAddToScene(%this)   
{   
	%this.SpeechPos = SpeechDisplayBehavior.SpeechDest;   
}   

function SpeechText::onAddToScene(%this)   
{   
	%YPOS = speechDisplayBehavior.Speaker.Position.Y - 8;   
	speechDisplayBehavior.TextPos = speechDisplayBehavior.Speaker.position.X SPC %YPOS;   
}

SpeechDisplayBehavior is a behavior template, not a behavior instance. If you get any information from that at all it would be whatever the default for the field is, not what the particular instance of the behavior has. You'll need to get the instance of the behavior off of the object that enters your trigger if you need to access this, but it looks like these are redundant since the DisplaySpeechBehavior manages this for itself.
#16
06/01/2013 (7:17 am)
Thanks a ton! Just a few things... After I press "C" it still skips to line 3, and oddly enough, if I press it again, it goes to line two, then goes in the normal order. While it is rendering "3" initially, it seems like it's trying to render two but it can't, judging by the fact you can see text from "2" flickering in and out of the box.
#17
06/02/2013 (7:32 am)
Sounds like it's going and adding another copy of the blurb somewhere anyway - double-check and ensure you're only adding it once.

If you have Torsion, step through it. Watch where it goes and what it does - this really helps.
#18
06/04/2013 (11:32 am)
Ah, thanks! That fixed one problem. I didn't use Torsion BTW, it doesn't work on Macs. :( I managed to fix the problem where it skipped from line one to line two and it had the flickering text. However, I still have the problem where it won't continue after line two and the problem where if I go out of the trigger then back in again, it has line 2, not the correct line 1. Here are the functions that I've changed:

function SpeechDisplayBehavior::textDone(%this)
{
Warn("Speech done!");

if(%this.speechLine = 0)
{
%this.speechLine = 1;
}

GlobalActionMap.bindObj("keyboard", "C", "nextLine", %this);
}

function speechDisplayBehavior::nextLine( %this )   
{   

%this.SpeechLine += 1;
echo("Added Speech line! <" @ %this.speechLine @ ">");


if(%this.numLines >= %this.SpeechLine && %this.numLines != 1 && %this.SpeechLine != 1)
{


if( !isObject(%this.Blurb) )
{
    %this.Blurb = new t2dStaticSprite()
    {
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        imageMap = "SpeechBubbleImageMap";  
        frame = "0";  
        sourceRect = "0 0 0 0";  
        canSaveDynamicFields = "1";  
        Position = %this.speechDest.position;  
        size = "50.000 20.000";  
        mountID = "173";
    };
}
    %textPosX = getWord(%this.Blurb.getPosition(), 0);
    %textPosY = getWord(%this.Blurb.getPosition(), 1);
    %blurbSizeY = getWord(%this.Blurb.size, 1);

    %textPos = %textPosX SPC %textPosY - 5;

if( !isObject(%this.SpText) )
{
    %this.SpText = new t2dTextObject(TextObj)
    {
        SceneGraph    = Scenewindow2D.getSceneGraph();  
        canSaveDynamicFields = "1";  
        Position = %textPos;
        SortPoint = "-0.161 -0.631";
        size = "48.000 3.000";  
        font = "Chalkboard";  
        text = " ";  
        wordWrap = "1";  
        BlendColor = "1 1 1 1";  
        hideOverflow = "0";  
        textAlign = "Left";  
        lineHeight = "3";  
        aspectRatio = "1";  
        lineSpacing = "0";  
        characterSpacing = "0";  
        autoSize = "0";  
        fontSizes = "84";  
        textColor = "1 1 1 1";  
        bilinearFilter = "0";  
        snapToInteger = "0";  
        noUnicode = "0";  
        hideOverlap = "0";  
        mountID = "174";  
    };
}

		%this.SpText.text = "";
		%this.blurbText = %this.NextText[%this.SpeechLine];
		%this.schedule(0, "typewriterText");

}
	else  
	{   
		if(%this.SpeechLine = 1)   
		{   
			error("First line!");   
		}   

    }
        if(%this.SpeechLine > %this.numLines)
        {
        error("Done.");
        }

}
#19
06/05/2013 (12:33 pm)
I recommend getting a real computer so you can debug your scripts with something better than rocks and sticks.... The only thing harder than debugging without proper tools is debugging without proper tools on an internet forum.

But, since you're stuck with caveman debugging, you should echo out the %this.SpeechLine along with the method name every time you change it. Then you'll at least know where it gets set and to what.

For example:
function SpeechDisplayBehavior::textDone(%this)  
{  
  Warn("Speech done!");  
  
  if(%this.speechLine = 0)  
  {  
    %this.speechLine = 1;
    echo(" @@@ %this.speechLine is now 1 - SpeechDisplayBehavior::textDone()");
  }  
  // by the way, why is this bind in this method?
  GlobalActionMap.bindObj("keyboard", "C", "nextLine", %this);  
}
#20
06/06/2013 (7:24 am)
Just so you know, the bind is in the method simply because I couldn't think of a better place to put it. Anyhow, I started echo'ing the functions:

Quote:Entered Area...
Created bubble
Speech done!
Initial Speech line! <1>
Added Speech line! <2>
Speech done!
Continue, but speech line is now at 1.
Initial Speech line! <1>
Added Speech line! <2>
Speech done!
Continue, but speech line is now at 1.
Initial Speech line! <1>

The problem seems to be that it keeps reseting the SpeechLine to 0, so how do I make it so that depending on what line it's supposed to be on, it changes it without just resetting it to 0 like we see here?
Page «Previous 1 2