Simple Script Problem
by Richard_H · in Torque Game Engine · 03/02/2006 (4:41 pm) · 13 replies
Thx, I'll try it
About the author
#2
03/02/2006 (5:20 pm)
Harold is correct. You could change it to $times to make it global, or put the times variable into the players namespace... ie %this.times
#3
datablock StaticShapeData(LaunchCrate)
{
category = "WeirdItems";
shapeFile = "~/data/shapes/crate/crate.dts";
};
function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
if(%this.times > 1){
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %this.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%this.times = %this.times + 1;
}
else{
echo('First time called!');
%this.times = 2;
%col.applyImpulse("0 0 0", "0 0 50");
}
}
}
Also, the terminal continues to say '21' Please post if you can help with any bit of my code.
03/02/2006 (6:10 pm)
It didn't work. I don't want to use a global variable and tried %this.times and it didn't work. Here is my new code. datablock StaticShapeData(LaunchCrate)
{
category = "WeirdItems";
shapeFile = "~/data/shapes/crate/crate.dts";
};
function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
if(%this.times > 1){
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %this.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%this.times = %this.times + 1;
}
else{
echo('First time called!');
%this.times = 2;
%col.applyImpulse("0 0 0", "0 0 50");
}
}
}
Also, the terminal continues to say '21' Please post if you can help with any bit of my code.
#4
03/02/2006 (7:01 pm)
Instead of %this.times, just use $times for now. That should get it working.
#5
{
%obj.times = 1;
}
try that if that doesn't work just use $times or set up echo's to check the value of %obj.times
03/02/2006 (7:12 pm)
Function LaunchCrate::onAdd(%this,%obj){
%obj.times = 1;
}
try that if that doesn't work just use $times or set up echo's to check the value of %obj.times
#6
datablock StaticShapeData(LaunchCrate)
{
category = "WeirdItems";
shapeFile = "~/data/shapes/crate/crate.dts";
};
function LaunchCrate::onAdd(%this,%obj)
{
%obj.times = 1;
}
function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %this.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%this.times = %this.times + 1;
}
}
but now I get no impulse. Clearly there is something wrong with that function. Please help me as soon as possible, I want to get the hang on Torque Script.
03/03/2006 (3:53 am)
I tried changing the code to this:datablock StaticShapeData(LaunchCrate)
{
category = "WeirdItems";
shapeFile = "~/data/shapes/crate/crate.dts";
};
function LaunchCrate::onAdd(%this,%obj)
{
%obj.times = 1;
}
function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %this.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%this.times = %this.times + 1;
}
}
but now I get no impulse. Clearly there is something wrong with that function. Please help me as soon as possible, I want to get the hang on Torque Script.
#7
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %obj.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%obj.times = %obj.times + 1;
}
}
it should be %obj.times not %this.times %this = "Launchcrate" as in the datablock %obj is the object.
03/03/2006 (5:51 pm)
Function LaunchCrate::onCollision(%this, %obj, %col){
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %obj.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%obj.times = %obj.times + 1;
}
}
it should be %obj.times not %this.times %this = "Launchcrate" as in the datablock %obj is the object.
#8
I think that it believes that %obj.times is a string. Here is my code:
Function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %obj.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%obj.times = %obj.times + 1;
}
}
What should I do?
03/03/2006 (6:17 pm)
No luck. I am getting a lot of console messages like 21122, 21222, 21322, 21422, 21522, ect...I think that it believes that %obj.times is a string. Here is my code:
Function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %this.times @ ' times.');
%impulse = 50 * %obj.times;
%col.applyImpulse("0 0 0", "0 0 %impulse");
%obj.times = %obj.times + 1;
}
}
What should I do?
#9
should be
and
could be shortened to
finally I forgot to change the %this in the echo so the overall function should be
03/03/2006 (6:23 pm)
Okay sorry for above posts I must not have been thinking clearly%col.applyImpulse("0 0 0", "0 0 %impulse");should be
%col.applyImpulse("0 0 0", "0 0 "@%impulse);and
%obj.times = %obj.times + 1;
could be shortened to
%obj.times++;
finally I forgot to change the %this in the echo so the overall function should be
Function LaunchCrate::onCollision(%this, %obj, %col)
{
if(%col.getClassName() $= "Player")
{
echo('This has been called ' @ %obj.times @ ' times.');
%impulse = 50 * %obj.times;
%col.applyImpulse("0 0 0", "0 0 "@%impulse);
%obj.times++;
}
}
#10
Master Treb you were so helpful!
03/03/2006 (6:38 pm)
THANKS!!! This is totaly working! At last! Thanks you, thank you, THANK YOU!!!Master Treb you were so helpful!
#11
ex.
echo("%this = "@%this@"!");
03/03/2006 (6:41 pm)
Nice to hear. just to clarify to add a variable to a string you need an @ in betweenex.
echo("%this = "@%this@"!");
#12
03/03/2006 (7:25 pm)
I have another small question. How does loadMyMission() work? I got it to work during the GettingStarted.pdf, but no it starts to load, but then it just doesn't. Where can I change which mission it loads / which mission is default?
#13
03/04/2006 (6:16 am)
Nm, found the anwer on another forum
Torque Owner Harold "LabRat" Brown