RHillFake Posted September 29, 2014 Share Posted September 29, 2014 In my code, I have an internal timer that when it runs out will gosub to what is supposed to be something that will change what direction player 2 is pointing and then reset the timer. The problem with my code is that the rand will only work once. The timer setup: dim Timer1=f.g dim Timer2=h.j Timer1=20 Timer2=1 main Timer1=Timer1-Timer2 if Timer1=2 then gosub randomgenerator:Timer1=20 The random selector: randomgenerator if rand<20 && rand>0 then p1_orientation=1 if rand<40 && rand>19 then p1_orientation=2 if rand<60 && rand>39 then p1_orientation=3 if rand<80 && rand>59 then p1_orientation=4 if rand<100 && rand>79 then p1_orientation=5 if rand<120 && rand>99 then p1_orientation=6 if rand<140 && rand>119 then p1_orientation=7 if rand<160 && rand>139 then p1_orientation=8 if rand<180 && rand>159 then p1_orientation=9 if rand<200 && rand>179 then p1_orientation=10 if rand<220 && rand>199 then p1_orientation=11 if rand<240 && rand>219 then p1_orientation=12 return Thanks! Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 29, 2014 Author Share Posted September 29, 2014 I found out that the score is affecting it. I had score=score-1 (6000-1) and when I changed the score to rand then it would affect the first 2 numbers and leave the 6000 in the four on the right. If I put score=score-1 and then score=rand beneath that it will work how I want it but the first two score numbers will randomly change while only the four on the right will be affected by the score=score-1. I will post source code later. Quote Link to comment Share on other sites More sharing options...
bogax Posted September 29, 2014 Share Posted September 29, 2014 (edited) rand is different every time you use it (and it takes time to calculate each time) edit: Wrong! an if statement just uses the current value of rand without calling the rand routine your code should be fine but.. Do this instead p1_orientation = rand/2 : (p1_orientation/2 + p1_orientation)/16 + 1 Rand goes from 0..255 That takes rand and multiplies it by .75/16 and adds 1 (rand * .75)/16 gives you a number 0..11) edit perhaps I should point out that that always sets p1_orientation to a number between 1..12 yours would skip it if rand > 240 Edited September 30, 2014 by bogax 1 Quote Link to comment Share on other sites More sharing options...
RHillFake Posted September 30, 2014 Author Share Posted September 30, 2014 rand is different every time you use it (and it takes time to calculate each time) edit: Wrong! an if statement just uses the current value of rand without calling the rand routine your code should be fine but.. Do this instead p1_orientation = rand/2 : (p1_orientation/2 + p1_orientation)/16 + 1 Rand goes from 0..255 That takes rand and multiplies it by .75/16 and adds 1 (rand * .75)/16 gives you a number 0..11) edit perhaps I should point out that that always sets p1_orientation to a number between 1..12 yours would skip it if rand > 240 Thanks, but your line only works as p1_orientation = rand/2 : p1_orientation=(p1_orientation/2 + p1_orientation)/16 + 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.