Hey Everyone,
So I'm in the process of writing my game (if you haven't seen it already, check out my post about it here: viewtopic.php?f=5&t=80361), and have come across a problem with all of the columns of blocks appearing together. I put in some debug code with prints, and saw that when it randomises the number, the variable fluctuates between 1 and 2 for a few seconds before settling on 1 number. By this time, all of the columns of blue have spawned in 1 place. Am I calling the math.random function wrong or is there a bug in my code? Attached will be a .love file of the game.
Thanks!
math.random fluctuation
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
math.random fluctuation
- Attachments
-
- game.love
- (63.02 KiB) Downloaded 139 times
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
Re: math.random fluctuation
the randomness of math.random is correct if you print segNo just after the affectation line 21 you got something like this
but I didn't go through the code further
Code: Select all
1
1
2
2
2
1
1
2
2
2
2
1
2
1
1
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
1
2
1
1
1
1
1
2
1
1
1
2
2
1
1
2
2
2
1
1
2
2
2
2
1
2
1
1
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
1
2
1
1
1
1
1
2
1
1
1
2
2
1
1
1
1
1
2
2
2
1
1
2
2
2
2
1
2
1
1
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
1
2
1
1
1
1
1
2
1
1
1
2
2
1
1
1
1
1
1
Re: math.random fluctuation
Sorry... How does this help me? It is useful to know what the output is, but I don't understand why it is useful. I want to know how to fix the fluctuation, not what the output is.
Thanks!
Thanks!
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: math.random fluctuation
Math.random should fluctuate I believe.
Re: math.random fluctuation
I dont see what your problem is here. Game seems to be working fine and math.random(1,2) works exactly as expected, it returns an integer between 1 and 2 (aka one of both) at random. math.random obviously may return a different number every time, that is what it's for.
Re: math.random fluctuation
I had a look at it and I cannot reproduce the problem. Can you explain in more detail, how to reproduce it?MattyAB wrote:I put in some debug code with prints, and saw that when it randomises the number, the variable fluctuates between 1 and 2 for a few seconds before settling on 1 number. By this time, all of the columns of blue have spawned in 1 place.
Check out my blog on gamedev
Re: math.random fluctuation
This is really strange. It sometimes does not do any randomisation and just puts the second number back to 3, but sometimes does the weird fluctuating thing. Press space to play, then watch it through a few times and you will see it happens after the 2nd number is 12. Attached will be a .love just in case I've made any unknown changes that I forgot about.
Thanks!
Thanks!
- Attachments
-
- game.love
- (49.1 KiB) Downloaded 121 times
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
Re: math.random fluctuation
Does anyone know why this is happening? Help would be appreciated.
Check out my blog - The place to find out about the latest tech news! http://thegeekcircle.blogspot.co.uk/
Re: math.random fluctuation
I don't have a complete solution for you but I noticed something: Whenever the random flickering occurs, at the right side of the screen two block appear one on top of the other (usually leaving no gap at all). So I think your block-generation logic is broken somewhere. You should start digging there.
Check out my blog on gamedev
Who is online
Users browsing this forum: Bing [Bot], pgimeno and 8 guests