Data Realms Fan Forums http://45.55.195.193/ |
|
Surprise Surprise http://45.55.195.193/viewtopic.php?f=73&t=15768 |
Page 1 of 1 |
Author: | Mind [ Wed Jul 08, 2009 5:58 pm ] |
Post subject: | Surprise Surprise |
How do i use mamth.random to generate three different results? Like this: Code: math.random(1,3) == x if x == 1 then blah blah end if x == 2 then blah blah end if x == 3 then blah blah end end Pretty sure this doesn't work though. |
Author: | Roon3 [ Wed Jul 08, 2009 6:25 pm ] |
Post subject: | Re: Surprise Surprise |
How about: Code: x = math.floor(math.random(1,3)); if x == 1 then blah blah end if x == 2 then blah blah end if x == 3 then blah blah end end |
Author: | Mind [ Wed Jul 08, 2009 6:37 pm ] |
Post subject: | Re: Surprise Surprise |
I'll try that :3 Edit: Also, if you wanted a timer to start once something happened, how would you go at doing that? I think you aren't sposed to just do Code: if blah blah then self.timer = Timer(); end I think that's buggy/doesn't work. Like if the actor is crouched for more than 20 seconds, then blah blah. |
Author: | mail2345 [ Wed Jul 08, 2009 7:25 pm ] |
Post subject: | Re: Surprise Surprise |
Code: timer:Reset() And try: Code: if math.floor(math.random(1,3)) == 1 then blah blah end if math.floor(math.random(1,3)) == 2 then blah blah end if math.floor(math.random(1,3)) == 3 then blah blah end end |
Author: | TheValiant [ Wed Jul 08, 2009 7:47 pm ] |
Post subject: | Re: Surprise Surprise |
When you use the math.random function with Lua, does it give you a different result every time, or do you have to call some sort of randomize function? I.e. math.random = 5 math.random = 5 randomize() math.random = 3 If there is no need for a randomize function, then (@Mail) your code will return a different random number every time it is called, and you might have code from two of the if-statement-blocks run. |
Author: | Grif [ Wed Jul 08, 2009 10:20 pm ] |
Post subject: | Re: Surprise Surprise |
http://lua-users.org/wiki/MathLibraryTutorial Quote: math.random(lower, upper) generates integer numbers between lower and upper. No math.floor needed, no randomize needed. So here's what I'd suggest: v = math.random(1,3); if v == 1 then whatever elseif v == 2 then whatever else whatever end |
Author: | mail2345 [ Wed Jul 08, 2009 10:29 pm ] |
Post subject: | Re: Surprise Surprise |
Ohh, it appears I mis interpeted what The Mind asked. I thought he meant how you could create 3 diffrent numbers with math.random Grif is right. |
Author: | Geti [ Thu Jul 09, 2009 12:50 am ] |
Post subject: | Re: Surprise Surprise |
Code: function Create(self) self.timer = Timer(); self.firsttimer = true end function Update(self) if blah blah and self.firsttimer then self.timer:Reset() end if self.timer:IsPastSimMS(number) and not self.firsttimer then stuff end end |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |