Game Development Community

My warp behavior is having... well... behavior issues [SOLVED]

by Orion the Hunter · in Torque Game Builder · 11/20/2012 (6:39 pm) · 6 replies

Hello, I recently made a warp behavior that should teleport the player to a set position. However, It keeps teling me that the coordinates are not a function. Can you make sense of that? Here is my code:

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

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

    %template.friendlyName = "Warp system";
    %template.behaviorType = "Collectable";
    %template.description  = "Warps the player to a position";

    %template.addBehaviorField( Position, "On enter, warp to here.", DEFAULT, "" );
}

function WarpPickupBehavior::confirmPickup( %this, %targetObject, %inventoryItem )
{

    $game::Player.Position = %this.Position;

    return true;
}

All I want to do is make a field that I can edit. Whatever I write in there should be the coordinates to warp to. Thanks!

#1
11/20/2012 (8:01 pm)
Jack,

So for warp in my platformer, I use a behavior that has separate "targetX" and "targetY" fields, both which are ints, not Position. This is a very simple and doable work-around.

You should tell us what you are trying to give to the TGB editor as a position.
#2
11/21/2012 (6:53 am)
For the location I want it to teleport me to

X: 2517.070
Y: -217.796


Thanks, Kevin!
#3
11/21/2012 (10:30 am)
Oh, sorry for not asking earlier, but would you mind positing your warp code? That would be greatly appreciated.
#4
11/21/2012 (11:37 am)
You'll have to practice a little bit of reverse engineering here. Some code statements in the following blocks are specific to my game and you'll have to change them for yours.

if (!isObject(teleportTriggerBehavior))
{
    %template = new BehaviorTemplate(teleportTriggerBehavior);
   
    %template.friendlyName = "Teleport Trigger";
    %template.behaviorType = "Physx Object Trigger";
    %template.description  = "Create a trigger object that teleports the player to a new position";

    %template.addBehaviorField(targetX, "The player's new X position.", float, 0.0);
    %template.addBehaviorField(targetY, "The player's new Y position.", float, 0.0);
    %template.addBehaviorField(resetTime, "How long it takes the trigger to reset.", int, 5000);
}

function teleportTriggerBehavior::onBehaviorAdd(%this)
{   
   if(%this.owner.getClassName() $= "t2dStaticSprite")
   {
      %this.owner.imageMap = "boxImageMap";
      %this.owner.class = "button";
      %this.owner.size = "1.5 1.5";
      %this.owner.blendColor = "0 1 0";
   }
      
   else if(%this.owner.getClassName() $= "t2dTextObject")
      %this.owner.class = "console";
      
   %this.owner.setLayer(5);
   %this.owner.setGraphGroup(5);
   %this.owner.setCollisionActive(true, true);
   %this.owner.setCollisionPhysics(false, false);
   %this.owner.setCollisionCallback(true);
   %this.owner.setCollisionLayers(3);
   %this.owner.setCollisionGroups(2);
   %this.owner.setCollisionMaxIterations(1);
   %this.owner.setCollisionResponse(CLAMP);
}

function teleportTriggerBehavior::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
   %player = %dstObject.parent;
   
   if(isObject(%player))
   {
      if(%srcObject.owner.class $= "button" && %player.getName() $= "playerOne")
      {
         if(!%srcObject.owner.on)
            %srcObject.activate();
      }
   }
}

function teleportTriggerBehavior::activate(%this)
{
   NL_SEManager.PlayAndSet(ActivateSEProfile, "soundEffect", "nonlooping", 3);
   
   screen.setBlendColor(1, 1, 1, 1);
   screen.fadeOut(0.025, 50, 0);
   playerOne.setPosition(%this.targetX SPC %this.targetY);   
         
   %this.owner.on = true;
   %this.owner.blendColor = "0 0.5 0";
   %this.owner.setCollisionActive(false, false);
   %this.owner.schedule(%this.resetTime, "setFieldValue", "on", "0");
   %this.owner.schedule(%this.resetTime, "setFieldValue", "blendColor", "0 1 0");
   %this.owner.schedule(%this.resetTime, "setCollisionActive", true, true);
   
   if(%this.owner.class $= "console")
      %this.owner.createExpression(sceneWindow2D.getSceneGraph().mathTier);
}

I suppose the key things are "targetX" and "targetY" as ints, and then
%player.setPosition(%this.targetX SPC %this.targetY);

In my game, the player runs over the button to trigger the collision, which then knows to teleport him to somewhere else in the level.
#5
11/21/2012 (12:26 pm)
Alright! I got it to work. :)

So I basically messed around with your code until I got this:

if (!isObject(WarpPickupBehavior))
{
    %template = new BehaviorTemplate(WarpPickupBehavior);
   
    %template.friendlyName = "Warp Behavior";
    %template.behaviorType = "Physx Object Trigger";
    %template.description  = "Create a trigger object that teleports the player to a new position";

    %template.addBehaviorField(targetX, "The player's new X position.", float, 0.0);
    %template.addBehaviorField(targetY, "The player's new Y position.", float, 0.0);
}

function WarpPickupBehavior::confirmPickup( %this, %targetObject, %inventoryItem )
{
   %player = $game::player;
   
   if(isObject(%player))
   {
   %player.Position = %this.targetX SPC %this.targetY;   

   }
}

Now I can get it to teleport me the right way. Once again, thanks Kevin! I'll probably elaborate on this a bit, but for a base, this is great!
#6
11/21/2012 (12:59 pm)
Awesome! Glad you got it working.