Following a tutorial... does it tell you to do the wrong thing?
by Ricky Hopper · in Torque Game Builder · 03/22/2009 (11:38 am) · 5 replies
Hey,
I'm doing one of the tutorials included in TGB to learn how to code (the WackAMole one) and in the code, it seems like they do something wrong. It has this line of code:
%mole.setPosition( %respawnPoint.getPosition() );
setPosition uses 2 integers as parameters, while getPosition outputs a string in the form of "<xcoord> <ycoord>". When the mole pops up, it appears in the center of the screen, probably because of this. Is there any way to convert the output of getPosition to be used by setPosition? I'm still new to this, so I'm not quite sure.
I'm doing one of the tutorials included in TGB to learn how to code (the WackAMole one) and in the code, it seems like they do something wrong. It has this line of code:
%mole.setPosition( %respawnPoint.getPosition() );
setPosition uses 2 integers as parameters, while getPosition outputs a string in the form of "<xcoord> <ycoord>". When the mole pops up, it appears in the center of the screen, probably because of this. Is there any way to convert the output of getPosition to be used by setPosition? I'm still new to this, so I'm not quite sure.
About the author
Recent Threads
#2
03/22/2009 (1:06 pm)
You could always just try%mole.setPosition( %respawnPoint.getPositionX(), %respawnPoint.getPositionY() );and see what happens.
#3
%respawnPoint = %this.respawnPointSet.getObject(%respawnPointIndex);
That's the code for finding the spawn point. It looks fine to me. And I tried the getPositionX and getPositionY, no better.
03/22/2009 (2:52 pm)
%respawnPointIndex = getRandom(%this.respawnPointSet.getCount() - 1);%respawnPoint = %this.respawnPointSet.getObject(%respawnPointIndex);
That's the code for finding the spawn point. It looks fine to me. And I tried the getPositionX and getPositionY, no better.
#4
%text = "HelloWorld";
%singleValue = 32; (still a string)
%pos = "32 32"; (string containing 2 space separated values)
So getPosition() will result in grabbing the X and Y value as a single string ("X Y").
getPositionX() will just get the first value, as a string ("X")
The conversion, or lack there of, is not what is causing a bad offset for you.
03/22/2009 (3:52 pm)
Just to clarify things for you, TorqueScript is typeless. Everything in TS is a string%text = "HelloWorld";
%singleValue = 32; (still a string)
%pos = "32 32"; (string containing 2 space separated values)
So getPosition() will result in grabbing the X and Y value as a single string ("X Y").
getPositionX() will just get the first value, as a string ("X")
The conversion, or lack there of, is not what is causing a bad offset for you.
#5
I'm still not sure what's wrong with my code however... what things should I check?
03/22/2009 (4:30 pm)
Oh, alright. The whole size thing makes more sense now. I'm used to languages with types, thanks for that.I'm still not sure what's wrong with my code however... what things should I check?
Torque Owner Eric Paik
Purpose
Gets the position of the object.
Return Value - Vector
The position of the object.
The return value of getPosition() is fine.
I would recheck your code/project to make sure that %respawnPoint is set properly. My experience with the tutorials has been that they have been bug free by-in large.