jbs30000 Posted March 22, 2007 Share Posted March 22, 2007 I seem to be running into a problem using rand in a multibank game. In the first Tron, in the grid spiders game, I had 6 grid spiders that moved around using rand, yet, when I integrated the game into the main Tron game, which uses 14K, all of a sudden rand didn't work any more and the spiders just stayed in the same location. In my second version of Tron that I'm working on, so far using 8k, I'm trying to use rand when the timer in the main screen runs out to choose a game for the player. However, every time I test this out, the same game allways gets chosen. Is this a known bug or something? It doesn't make any difference if I use set optimization inlinerand either. Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted March 22, 2007 Share Posted March 22, 2007 (edited) Could you post the code? Have you used something like this? timer=timer+1 if timer=99 then timer=0 : w=rand if w<=64 then w=1 if w>64 && w<128 then w=2 if w>=128 && w<196 then w=3 if w>=196 then w=4 Edited March 22, 2007 by atari2600land Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted March 22, 2007 Share Posted March 22, 2007 I seem to be running into a problem using rand in a multibank game. In the first Tron, in the grid spiders game, I had 6 grid spiders that moved around using rand, yet, when I integrated the game into the main Tron game, which uses 14K, all of a sudden rand didn't work any more and the spiders just stayed in the same location. In my second version of Tron that I'm working on, so far using 8k, I'm trying to use rand when the timer in the main screen runs out to choose a game for the player. However, every time I test this out, the same game allways gets chosen. Is this a known bug or something? It doesn't make any difference if I use set optimization inlinerand either. If I understand it correctly, the initial value of rand is always the same when you play a game on an emulator, but it will be different when you play a game on a real 2600. A way to get around this is to call the rand function once on every frame during your title/menu screen, so that when the player chooses a game, the rand variable will contain a different value. As for using rand in a bankswitched game, it shouldn't make any difference, although it depends on how you're using rand. For example, I posted a "get_rand" function that can be added into a game to return a random value within a specified range-- e.g., "x = get_rand(1,6)" to get a random value between 1 and 6 inclusive-- but if you're going to call that function from different banks, you'll need to specifiy the bank, but I'm not sure how that should be done-- e.g., "x = get_rand(1,6) bank2"? Michael Quote Link to comment Share on other sites More sharing options...
jbs30000 Posted March 22, 2007 Author Share Posted March 22, 2007 atari2600land basically I use a timer to count down from 9 to 0 and then jump to a sub that uses rand to choose a game. The code for the routine is: TimerChoose b = rand if b <= 64 then goto ChooseUp if b <= 128 then goto ChooseDown if b <= 191 then goto ChooseLeft if b <= 255 then goto ChooseRight SeaGtGruff That's very interesting, and good to know. Since I only use an emulator I will do multiple instances of rand. Thanks. 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.