Debugging issue with getRandom
by Joao Brandao · in Technical Issues · 01/24/2012 (4:38 am) · 7 replies
I ran a debug using Torsion, on the game I'm creating on iTorque, and I get a recurrent error, which I really don't understant why it comes up as an error:
scripts/PowerUps.cs (757): ::getRandom - wrong number of arguments.
But it's really weird, because the line the error is talking about has just this:
As far as I know (although it's true I don't know much lol) that getRandom is used properly. When it runs inside the function I want it to return either a 1, a 2 or a 3.
Can someone help me with this?
Thank you in advance
scripts/PowerUps.cs (757): ::getRandom - wrong number of arguments.
But it's really weird, because the line the error is talking about has just this:
%corridorSpeedMinus = getRandom(1,3);
As far as I know (although it's true I don't know much lol) that getRandom is used properly. When it runs inside the function I want it to return either a 1, a 2 or a 3.
Can someone help me with this?
Thank you in advance
About the author
I'm a little old to start programming, as I'm 32, but being unemployed pushed me into learning new skills and go back to the area I graduated in (New Technologies). I am my own worst enemy, as I procrastinate a lot, and I'm very lazy. Also, I love games.
Recent Threads
#2
01/25/2012 (4:08 pm)
Looks good to me. Maybe another error is causing that one? Is that the only error?
#3
Actually, it's the same mistake repeated twice, and then it stops. I'm completely baffled by this one.
01/25/2012 (4:11 pm)
the exact error message I get is:scripts/PowerUps.cs (757): ::getRandom - wrong number of arguments. scripts/PowerUps.cs (757): usage: ([ min ],[ max ]) Use the getRandom function to get a random floating-point or integer value. This function comes in three forms. The first getRandom() takes no arguments and will return a random floating-point value in the range of 0.0 to 1.0. The second getRandom( max ) takes one argument representing the max integer value this will return. It will return an integer value between 0 and max. The third getRandom( min , max ) takes two arguments representing the min and max integer values this will return. It will return an integer value between min and max. Only the no-args version will return a floating point. @param min Minimum inclusive integer value to return. @param max Maximum inclusive integer value to return. @return If no arguments are passed, will return a floating-point value between 0.0 and 1.0. If one argument is passed, will return an integer value between 0 and max inclusive. If two arguments are passed, will return an integer value between min and max inclusive. @sa getRandomSeed
Actually, it's the same mistake repeated twice, and then it stops. I'm completely baffled by this one.
#4
01/25/2012 (4:50 pm)
in fact, let me post the entire function where the getRandom is being used, just to make things clearer.function PowerUpSpeedMinusReset()
{
%corridorSpeedMinus = getRandom(1,3);
switch(%corridorSpeedMinus)
{
case 1:
if ($spawnCorridor1)
{
$spawnCorridor1 = false;
PowerUpSpeedMinus.setPositionX(700);
PowerUpSpeedMinus.setPositionY(-212);
PowerUpSpeedMinus.setLinearVelocityX(-200);
}
else
{
PowerUpSpeedMinusReset();
}
case 2:
if ($spawnCorridor2)
{
$spawnCorridor2 = false;
PowerUpSpeedMinus.setPositionX(700);
PowerUpSpeedMinus.setPositionY(-135);
PowerUpSpeedMinus.setLinearVelocityX(-200);
}
else
{
PowerUpSpeedMinusReset();
}
case 3:
if ($spawnCorridor3)
{
$spawnCorridor3 = false;
PowerUpSpeedMinus.setPositionX(700);
PowerUpSpeedMinus.setPositionY(-60);
PowerUpSpeedMinus.setLinearVelocityX(-200);
}
else
{
PowerUpSpeedMinusReset();
}
}
}
#5
Your 'else' statements keep recursively calling the same function (PowerUpSpeedMinusReset()) so, eventually, you overflow the call stack.
If you remove the else statements, your function will work.
01/27/2012 (12:45 pm)
The error message is wrong, your bug is being caused by stack overflow.Your 'else' statements keep recursively calling the same function (PowerUpSpeedMinusReset()) so, eventually, you overflow the call stack.
If you remove the else statements, your function will work.
#6
01/27/2012 (1:34 pm)
I'll give it a try and see if it works. I have to find a way to get around those else statements (i do need them) and I'll let you know if it worked. Thank you so much for your help!
#7
turns out I had simply forgot to update some values in another variables. stupid me...
Thank you once again, without you calling out my attention to the else statements I probably would have taken a LOOOOOONG time to discover that.
01/28/2012 (8:04 am)
OK, I got it, finally. And as usual, it was a pretty simple solution. I couldn't get rid of those else statements because they are needed and I would have to change a big portion of the code. But the problem with the else statements was relatively new, so something had to have happened for them to cause a stack overflow.turns out I had simply forgot to update some values in another variables. stupid me...
Thank you once again, without you calling out my attention to the else statements I probably would have taken a LOOOOOONG time to discover that.
Joao Brandao
Tricephalus