Game Development Community

Random horizontal position

by Aaron Varshney · in Torque Game Builder · 03/12/2005 (3:41 pm) · 3 replies

I've looked through the tutorial and you've shown that in order to get the vertical random positions you used:
$enemy.setPosition("40" SPC (-30 + (getRandom() * 60)));
This works fine however if I reverse the value so that the horizontal position gets the random position:
$enemy.setPosition(SPC(-30+(getRandom()*60)) "40");
Nothing compiles and I get the error:
>>> Advanced script error report.  Line 253.
>>> Some error context, with ## on sides of error halt:
^$easyEnemy.setImageMap(Easy_Enemy);

^$easyEnemy.setSize("9 7");

^$easyEnemy.setPosition(SPC ##(##-30+(getRandom()*60))"40");

^$easyEnemy.setLinearVelocityY(25);
>>> Error report complete.
Has anyone else had a similar problem or am I doing something completely wrong?

#1
03/12/2005 (3:49 pm)
-- nevermind! Harold's solution works :)
#2
03/12/2005 (3:56 pm)
Quote:$enemy.setPosition(SPC(-30+(getRandom()*60)) "40");

Should be

$enemy.setPosition( ( -30 + ( getRandom() * 60 ) ) SPC "40" );
#3
03/12/2005 (3:56 pm)
I get the same error, strange how it works fine for the Y Axis.
Edit : AHA! That works, now I need to get them to display in the correct place, cheers.