Data Realms Fan Forums
http://forums.datarealms.com/

math.random error
http://forums.datarealms.com/viewtopic.php?f=73&t=25846
Page 1 of 1

Author:  Asklar [ Thu Oct 13, 2011 9:36 pm ]
Post subject:  math.random error

Bad argument #1 to "random" (interval is empty)

I thought I had fixed it, but I didn't, but the errors were very random, so I didn't care much, but now it's bugging me seriously.

What produces this error?

Author:  Asklar [ Thu Oct 13, 2011 10:56 pm ]
Post subject:  Re: math.random error

Code:
   self.LaserMaxDist = SceneMan:CastObstacleRay(self.MuzzlePos, Vector(1600*self.reverseNum,0):RadRotate(self.RotAngle),Vector(),self.LaserPos,self.ID,0,0)
      if self.LaserMaxDist < 0 then
         self.LaserSight = 1600
      else
         self.LaserSight = self.LaserMaxDist
      end


math.random(self.LaserSight) is what I'm using, but I'm using it later.

Author:  Grif [ Fri Oct 14, 2011 3:49 am ]
Post subject:  Re: math.random error

Make absolutely sure that an actual value is getting passed into math.random. Try printing self.LaserSight and firing the gun a few times. Or, y'know, doing whatever action triggers the script.

Author:  Asklar [ Fri Oct 14, 2011 7:51 pm ]
Post subject:  Re: math.random error

I'll try printing it to see what happens.

Author:  Asklar [ Sat Oct 15, 2011 7:36 pm ]
Post subject:  Re: math.random error

Fixed it, the error ocurred when I aimed at pointblank and the ray result was 0.
So, I changed the else into
Code:
elseif self.LaserMaxDist >= 0 then
  self.LaserSight = math.max(1, self.LaserMaxDist)

and it worked fine.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/