Game Development Community

Starter.fpS problem (Trying to Scale object)

by Marvin Hawkins · in Torque Game Engine · 11/20/2008 (7:27 am) · 12 replies

Hello All,

I bought torque four years ago and I'm finally getting a chance to use it for something! I'm working on a prototype for "Game prototyping" Class. I want to use Torque to make an environmental puzzle game. Part of the game is to get the character to "scale" himself to fit through different parts of the world.

Part of the problem is that I'm coming from a different coding enviroment (blitz 3d) it's fairly simple. I have a programming background and have read through both the Torque tutorial and 3D Game Programming all in one.

I think I have a fairly good idea of where and how to mode the game to suit my needs. But I have a few questions that I can't quite figure out.


1) Is there a predefined function for scaling?

2) Where can I find a set of predefined functions. (like a manual)

3) Are there any offline resources? TDN has been down for 2 days for me.

4) Also is it better to start completely with the tutorial base for this type of project or is the starter.fps still a good one to start.


I know this is a lot of requests, but I appreciate any help you all can provide

#1
11/20/2008 (8:01 am)
1) setScale(xscale, yscale, zcale) on a gamebase/shapebase derived object should do the trick.

2) TDN if anywhere... the source is better but of course harder to read for some

3) There was a .chm somewhere once of Torque stuff, you can try googling Torque tutorials

4) If you like most of the features in starter.fps use that, if not, don't!

Good luck, and welcome back!
#2
11/20/2008 (9:14 am)
Hmm thanks Dave I tried to do.


SetScale(x y z)

Inside the player datablock in player.cs with no luck.


function Player::Scale(%this)
{
%this.SetScale("500 100 100");
}


Why does this not work? Is Scale outside the scope of the player's functions? Am I doing Method Functions correctly?

I did some research it looks like there are two player.cs files in the base Starter.FPS tutorial, this one in Server is where most of the methods happen.

the player.cs in "~/data/shapes/player"
#3
11/20/2008 (9:20 am)
I think it's setScale(500,100,100);

add some echos to make sure it's getting called, and check your console for errors
#4
11/20/2008 (9:46 am)
Ok. I checked my Echoes on it. No errors.

Where else in torque is the player datablock defined?

Am I even calling methods the right way?
#5
11/20/2008 (10:10 am)
Actually setScale will not work on a datablock, you need to apply it on an object.

from player.cs:
function Armor::onAdd(%this,%obj)
{
   // Vehicle timeout
   %obj.mountVehicle = true;

   // Default dynamic armor stats
   %obj.setRechargeRate(%this.rechargeRate);
   %obj.setRepairRate(0);

   %obj.setScale("10 10 10");
}
That will scale the player object 10X larger when it is spawned, and note that the quotes are necessary.

If you want to dynamically scale the player throughout the game you'll need to acquire the objectId (not the datablock) and apply setScale on it.
#6
11/20/2008 (10:26 am)
Oh my god thank you! It works like a charm!

One Question though, Is Armor a part of the Datablock?

I'm having some trouble understanding Datablocks and Methods. A datablock is a list of properties. and A method is a type of function.

But what is the

"Variable"::Method

That comes before the double semicolon?
#7
11/20/2008 (10:32 am)
I guess I missed that you were trying this on a datablock... sorry!
#8
11/20/2008 (10:41 am)
Oh my god thank you! It works like a charm!

One Question though, Is Armor a part of the Datablock?

I'm having some trouble understanding Datablocks and Methods. A datablock is a list of properties. and A method is a type of function.

But what is the

"Variable"::Method

That comes before the double semicolon?
#9
11/20/2008 (12:29 pm)
Oh and sorry to bug everyone. But I'm trying to set up a function that when a player presses a button his scale changes.


Here's my logic.

In the player.cs I'm defining a new Method that affects the "ARMOR" object. Which is an object of the Player Datablock (right? or wrong?)

This function is:

function Armor::SetPlayerScale( %obj)
{
%obj.setScale();
}

and then If i set a movemap.keybind. it will call the function "SetplayerScale" is my logic correct?
#10
11/20/2008 (2:07 pm)
You were correct in your surmise that datablocks are a collection of properties. Methods (also called functions) are just a means of doing something. The name::method() "::" association is just that - a name. In Torquescript it's called Namespace. The reason that example I gave you used "Armor" is because the PlayerBody datablock was given the script class of Armor. Take a look at the PlayerBody datablock and you'll see the field className = Armor;

It seems complicated at first but it really simplifies things in the end. Take a look at the other Armor methods in player.cs. Every one of those could have used PlayerBody::Method(). But what happens if you have 10 PlayerBody datablocks? You'll need an ::onAdd, ::onRemove, ::onMount, ::onCollision, etc, etc for each of them. You end up with duplicate functions whose only difference is their name. What that className = Armor field does is allow us to preface those methods with Armor instead of the name of every player datablock that we have defined. This allows you to share similar code for similar things.

On to your last question. Armor (in this case) as you can now see is just a common Name (namespace) for a group of datablocks and isn't an object per se. Objects are the actual instance(s) that exists in the game world. Datablocks describe these objects. And methods control them.

I really hope that makes sense.

To set up keybinds so that you can scale the player will require learning about server and client commands. I'm not going to go into a lot of detail here because I need to go. I'm also going to cheat and work around the whole obtaining the objectID thing. But if you have questions, feel free to ask them. I'll try to get back later.

This will scale the player based on a preset scale set to a keybind.
function serverCmdScalePlayerHalf(%client)
{
    %client.player.setScale("0.5 0.5 0.5");
}

function serverCmdScalePlayerNormal(%client)
{
    %client.player.setScale("1 1 1");
}

function serverCmdScalePlayerDouble(%client)
{
    %client.player.setScale("2 2 2");
}

moveMap.bindCmd(keyboard, "alt 1", "commandToServer(\'ScalePlayerHalf\');", "");
moveMap.bindCmd(keyboard, "alt 2", "commandToServer(\'ScalePlayerNormal\');", "");
moveMap.bindCmd(keyboard, "alt 3", "commandToServer(\'ScalePlayerDouble\');", "");
This works but may not be the best way of doing it, it was just the quickest example I could show you.
#11
11/20/2008 (6:26 pm)
Oh wow thank you! i can completely undersand that. Thank you for that, It worked like a charm.

One more question. when you're doing the %client.player.setscale for example,

can you pass the player parameter through this function because it is already previously defined?
#12
11/20/2008 (8:24 pm)
Well sort of, because the game is already tracking the client and it's controlled object (the player), you can get away with it. But it can fail in some situations and possibly crash the game - or just not work.

Glad I was able to help, I'm not all that good at explanations. I learn from the example of the existing code/script and my brain is a crazy place. One of these days I may get around to actually reading the documentation that exists here - I hear it's highly recommended these days.