Game Development Community

TorqueScript Question

by Sean Yeomans · in Technical Issues · 07/03/2008 (5:31 am) · 6 replies

Hi guys,

I'm here trying to learn some of the ropes of Torquescript. I have a silly problem thats probably easy for you guys to solve.

I've made a new t2dAnimatedSprite and I'm hard coding its position on the screen by passing in its position as an argument:

$playerLoaded = newPlayer("200 200");

Heres my code that creates the player:

function newPlayer(%playerLoc)
{
%thePlayer = new t2dAnimatedSprite()
{
scenegraph = $thescenegraph;
animationName = "evilgnomesheetAnimation";
canSaveDynamicFields = "1";
Position = %playerLoc; // <-------------------------------- This code uses the position passed in
size = "75.000 75.000";
class = "playerClass";
};

return %thePlayer;
}

So that works fine, but when I set two variables above and pass those into the newPlayer call, it doesn't work:

%xPos = 200;
%yPos = 200;
$playerLoaded = newPlayer("%xPos %yPos");



Any ideas?

Thanks!

#1
07/03/2008 (5:39 am)
I think you need to remove the quotes from ("%xPos %yPos"). Using quotes will treat it as a string.
#2
07/03/2008 (5:51 am)
Thanks for the suggestion, but I've tried that and it didn't work.
#3
07/03/2008 (5:55 am)
Try:
newPlayer(%xPos SPC %yPos)

SPC adds a blank space when concatenating, alternatively use @ for no space.

Gabriel
#4
07/03/2008 (5:57 am)
I'm not sure if this is your problem, but try:
$playerLoaded = newPlayer(%xPos SPC %yPos);

Does you console show any errors?

EDIT- Opps, Gabriel got to ya first. ;)
#5
07/03/2008 (6:04 am)
Sweet that works, thanks guys!
#6
07/03/2008 (8:04 am)
Going through the first few chapters of the book "The Game Programmer's Guide To Torque" is a great way to come up to speed on torquescript.