Rabbit 2600 Posted June 14, 2013 Share Posted June 14, 2013 (edited) Well, I've just begun with gosubs. And I'm in a bit of trouble. I can't get this sub to work right. The flash effect works great if it's in the main loop, but when I put it in the sub the flash never ends. What gives? if collision(player0,ball) then gosub __Flash __Flash bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 return The code without the gosub: if collision(player0,ball) then bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 if n > 0 then AUDV0 = 8 : AUDC0 = 2 : AUDF0 = 18 : n = n - 1: if n = 0 then AUDV0 = 0 if p > 0 then AUDV0 = 8 : AUDC0 = 4 : AUDF0 = 20 : p = p - 1: if n = 0 then AUDV0 = 0 Edited June 15, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 Well, I've just begun with gosubs. And I'm in a bit of trouble. I can't get this sub to work right. The flash effect works great if it's in the main loop, but when I put it in the sub the flash never ends. What gives? if collision(player0,ball) then gosub __Flash __Flash bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 return The code without the gosub: if collision(player0,ball) then bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 if n > 0 then AUDV0 = 8 : AUDC0 = 2 : AUDF0 = 18 : n = n - 1: if n = 0 then AUDV0 = 0 if p > 0 then AUDV0 = 8 : AUDC0 = 4 : AUDF0 = 20 : p = p - 1: if n = 0 then AUDV0 = 0 It looks like you included stuff in your gosub that needs to run every time, not just when there is a collision. Unless I'm doing something that needs to be used by more than one spot in my program, I don't use gosub. I'd do this instead: if !collision(player0,ball) then goto __Skip_Coll_P0_Ball score = score + 40 : p = 11 bally = 255 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 __Skip_Coll_P0_Ball q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 if n > 0 then AUDV0 = 8 : AUDC0 = 2 : AUDF0 = 18 : n = n - 1: if n = 0 then AUDV0 = 0 if p > 0 then AUDV0 = 8 : AUDC0 = 4 : AUDF0 = 20 : p = p - 1: if n = 0 then AUDV0 = 0 Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 (edited) It's a feature I need in all my screens, so I thought I could save some memory by doing this as a sub. Maybe it's not possible with this? Incase things needs closer examination, here's the source: default.bas I took out everything except q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 in the sub but the flash still never ends. Edited June 15, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 It's a feature I need in all my screens, so I thought I could save some memory by doing this as a sub. Maybe it's not possible with this? Does each screen have a separate loop or is it all done in the main loop? Whatever the answer, you can't hide a gosub in an if-then that only happens when there is a collision that contains stuff that is supposed to run all of the time. You'd need to use something like you see below. This would be in your main loop: if collision(player0,ball) then bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 gosub __Moose_Fart And this would be outside of your main loop: __Moose_Fart q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 return Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Each screen is a separate loop. All screens are exactly alike except for the playfield. I tried doing the same thing you proposed but the flash still runs infinitely. Hm. Is there a way to just have the playfield change when the player leaves the screen and erase the need to copy the first loop for each screen? Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Okay, fixed it. I used this code in the main loop and now the screens change and keeping everything at a minimum size. Thank you Random Terrain. Talking with you gets my brain going =) Screen_1 if k = 1 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............... ................ ................ X............... XXXXXXXXXXXXXX.. end drawscreen Screen_2 if k = 2 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X.....X......... ......X........X ...X.....X.....X X..X.....X...... XXXXXXXXXXXXXX.. end Screen_3 if k = 3 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............X.. ................ ......XX........ X.....XX.....X.. XXXXXXXXXXXXXX.. end Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 However, now I can't leave the titlescreen. Hm. Any thoughts? includesfile multisprite_bankswitch.inc set kernel multisprite set romsize 8k set optimization size set smartbranching on AUDV0 = 0 : AUDC0 = 0 : AUDF0 = 0 playfield: ................ ................ ................ ................ ................ .....XXX........ ...XXXXXXX....XX ....XXXXX...XXXX ....XXXXXXXXXXXX ....XX.XX.XX.XXX ....XXXXXXXXXXX. end title COLUPF = $00 COLUBK = $40 end drawscreen if joy0fire || joy1fire then goto skiptitle goto title skiptitle player0x = 50 player0y = 50 player1x = 29 player1y = 79 player2x = 139 player2y = 79 player3x = 29 player3y = 33 player4x = 139 player4y = 33 bally = 47 ballx = rand dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P2_L_R = player2x.c dim _P2_U_D = player2y.d dim _P3_L_R = player3x.e dim _P3_U_D = player3y.f dim _P4_L_R = player4x.g dim _P4_U_D = player4y.h dim _P0_L_R = player0x.i dim _P0_U_D = player0y.j scorecolor = $0E COLUPF = $20 COLUBK = $00 _COLUP1 = $0A COLUP2 = $0A COLUP3 = $0A COLUP4 = $0A n = 0 p = 0 s = 1 Level_1 COLUP0 = $1A player0: %00011100 %00011000 %00011000 %00011000 %00011000 %00000000 %00011000 %00000000 end player1: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player2: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player3: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player4: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end Screen_1 if k = 1 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............... ................ ................ X............... XXXXXXXXXXXXXX.. end drawscreen Screen_2 if k = 2 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X.....X......... ......X........X ...X.....X.....X X..X.....X...... XXXXXXXXXXXXXX.. end Screen_3 if k = 3 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............X.. ................ ......XX........ X.....XX.....X.. XXXXXXXXXXXXXX.. end if joy0right then _P0_L_R = _P0_L_R + 0.30 if joy0left then _P0_L_R = _P0_L_R - 0.30 if joy0up then _P0_U_D = _P0_U_D + 0.30 if joy0down then _P0_U_D = _P0_U_D - 0.30 if _P1_U_D < _P0_U_D then _P1_U_D = _P1_U_D + 0.03 if _P1_U_D > _P0_U_D then _P1_U_D = _P1_U_D - 0.03 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.03 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.03 if _P2_U_D < _P0_U_D then _P2_U_D = _P2_U_D + 0.07 if _P2_U_D > _P0_U_D then _P2_U_D = _P2_U_D - 0.07 if _P2_L_R < _P0_L_R then _P2_L_R = _P2_L_R + 0.07 if _P2_L_R > _P0_L_R then _P2_L_R = _P2_L_R - 0.07 if _P3_U_D < _P0_U_D then _P3_U_D = _P3_U_D + 0.10 if _P3_U_D > _P0_U_D then _P3_U_D = _P3_U_D - 0.10 if _P3_L_R < _P0_L_R then _P3_L_R = _P3_L_R + 0.10 if _P3_L_R > _P0_L_R then _P3_L_R = _P3_L_R - 0.10 if _P4_U_D < _P0_U_D then _P4_U_D = _P4_U_D + 0.15 if _P4_U_D > _P0_U_D then _P4_U_D = _P4_U_D - 0.15 if _P4_L_R < _P0_L_R then _P4_L_R = _P4_L_R + 0.15 if _P4_L_R > _P0_L_R then _P4_L_R = _P4_L_R - 0.15 if collision(player0,player1) then goto Game_Over k = 0 if player0x < 16 then player0x = 139 : k = (rand&3) : bally = 47 : ballx = rand : player1x = 29 : player1y = 79 : player2x = 139 : player2y = 79 : player3x = 29 : player3y = 33 if player0x > 138 then player0x = 16 : k = (rand&3) : bally = 47 : ballx = rand if player0y > 90 then player0y = 10 : k = (rand&3) : bally = 47 : ballx = rand if player0y < 10 then player0y = 90 : k = (rand&3) : bally = 47 : ballx = rand if k = 1 then goto Screen_1 : k = 0 if k = 2 then goto Screen_2 : k = 0 if k = 3 then goto Screen_3 : k = 0 if joy0right then _P0_L_R = _P0_L_R + 0.30 : n = 11 if joy0left then _P0_L_R = _P0_L_R - 0.30 : n = 11 if joy0up then _P0_U_D = _P0_U_D + 0.30 : n = 11 if joy0down then _P0_U_D = _P0_U_D - 0.30 : n = 11 if collision(player0,playfield) && joy0right then player0x = player0x - 3 if collision(player0,playfield) && joy0left then player0x = player0x + 3 if collision(player0,playfield) && joy0up then player0y = player0y - 3 if collision(player0,playfield) && joy0down then player0y = player0y + 3 if ballx < 16 then bally = 255 if ballx > 138 then bally = 255 if collision(player0,ball) then bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 if n > 0 then AUDV0 = 8 : AUDC0 = 2 : AUDF0 = 18 : n = n - 1: if n = 0 then AUDV0 = 0 if p > 0 then AUDV0 = 8 : AUDC0 = 3 : AUDF0 = 23 : p = p - 1: if n = 0 then AUDV0 = 0 goto Level_1 Game_Over playfield: ................ ................ ................ ................ ................ ..........XXX... ............XX.. ................ .............XXX ............XXXX ...........XXXX. end AUDV0 = 0 : AUDC0 = 0 : AUDF0 = 0 gameover COLUPF = $0E COLUBK = $00 player0x = 100 player0y = 100 player1x = 100 player1y = 100 player2x = 100 player2y = 100 player3x = 100 player3y = 100 player4x = 100 player4y = 100 end drawscreen if joy0fire || joy1fire then reboot goto gameover Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 You'll need to post a .bas file. It would probably help if you also posted the previous version that worked before you made the new changes. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Here is the version with multiple screens in 1 loop: default.bas And here is the version with the multiple loops: defaultold.bas Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 Here is a tip from this thread: Be sure to name your program files something other than 'default' in case you need to post them in the future. Even if you don't know the name of the game yet, you can always use your username mixed with the type of project. For example, if your username is Mr. Giggle Snort and you're working on an unnamed maze game, you could call it "giggle_snort_maze_game_2011y_04m_28d_1002t.bas". For more about naming your files, see Easy Software Versioning. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 I will take your tip to heart and rename the program files in the future. Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted June 15, 2013 Share Posted June 15, 2013 In order to keep myself sane(er) I usually code assuming the program is gonna look like this: DECLARE/DIM STUFF INIT GAME MAIN GAME START OF MAIN (HOUSEKEEPING, COUNTERS GOES HERE) DEAL WITH JOYSTICK DEAL WITH AI DEAL WITH COLLISIONS DRAW SCREEN END OF MAIN (CLEAN UP AND LOOP AROUND!) GENERIC ROUTINES AND USER FUNCTIONS GAME DATA Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Good idea theloon. I'll save this, I really need better structuring in my codes. They tend to be a big mess after a while. Especially this project. 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 I was expecting one program without gosubs and one with gosubs. I don't know which one you want to use. Anyway, here are your two programs with the extra ENDs removed: rabbit_multiple_screens_in_1_loop_2013y_06m_14d_2323t.bas rabbit_multiple_loops_2013y_06m_14d_2323t.bas You were using end in a couple of places in both programs when there shouldn't have been an end. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Thank you =) Mm, yes. I seem to have the "end curse" I'm still learning so I hope I am forgiven for such a foolish misstake =) Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Hm, having problems getting out of the titlescreen. When the firebutton is pressed player0 appears and can run around in the titlescreen instead of the rooms in the mainloop. Perhaps something is set in the wrong order? includesfile multisprite_bankswitch.inc set kernel multisprite set romsize 8k set optimization size set smartbranching on Title_Screen playfield: ................ ................ ................ ................ ................ .....XXX........ ....XX.XX.....XX ....XXXXXXXXXXXX ....XXXXX.XX.XXX ....XXXXXXXXXXX. ................ end title COLUPF = $00 COLUBK = $40 drawscreen if joy0fire || joy1fire then goto skiptitle goto title skiptitle dim _P1_L_R = player1x.a dim _P1_U_D = player1y.b dim _P2_L_R = player2x.c dim _P2_U_D = player2y.d dim _P3_L_R = player3x.e dim _P3_U_D = player3y.f dim _P4_L_R = player4x.g dim _P4_U_D = player4y.h dim _P0_L_R = player0x.i dim _P0_U_D = player0y.j AUDV0 = 0 : AUDC0 = 0 : AUDF0 = 0 player0x = 50 player0y = 50 player1x = 29 player1y = 79 player2x = 139 player2y = 79 player3x = 29 player3y = 33 player4x = 139 player4y = 33 bally = 47 ballx = rand scorecolor = $0E COLUPF = $20 COLUBK = $00 _COLUP1 = $0A COLUP2 = $0A COLUP3 = $0A COLUP4 = $0A n = 0 p = 0 s = 1 Level_1 COLUP0 = $1A player0: %00011100 %00011000 %00011000 %00011000 %00011000 %00000000 %00011000 %00000000 end player1: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player2: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player3: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end player4: %00001110 %00011011 %00011001 %00111100 %00111100 %01111110 %01111110 %11011011 %11000011 %11000011 %10100101 %10111101 %10011001 %10111101 %10011001 %10001101 end Screen_1 if k = 1 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............... ................ ................ X............... XXXXXXXXXXXXXX.. end drawscreen Screen_2 if k = 2 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X.....X......... ......X........X ...X.....X.....X X..X.....X...... XXXXXXXXXXXXXX.. end Screen_3 if k = 3 then playfield: ................ ................ ................ ................ ................ XXXXXXXXXXXXXX.. X............X.. ................ ......XX........ X.....XX.....X.. XXXXXXXXXXXXXX.. end if joy0right then _P0_L_R = _P0_L_R + 0.30 if joy0left then _P0_L_R = _P0_L_R - 0.30 if joy0up then _P0_U_D = _P0_U_D + 0.30 if joy0down then _P0_U_D = _P0_U_D - 0.30 if _P1_U_D < _P0_U_D then _P1_U_D = _P1_U_D + 0.03 if _P1_U_D > _P0_U_D then _P1_U_D = _P1_U_D - 0.03 if _P1_L_R < _P0_L_R then _P1_L_R = _P1_L_R + 0.03 if _P1_L_R > _P0_L_R then _P1_L_R = _P1_L_R - 0.03 if _P2_U_D < _P0_U_D then _P2_U_D = _P2_U_D + 0.07 if _P2_U_D > _P0_U_D then _P2_U_D = _P2_U_D - 0.07 if _P2_L_R < _P0_L_R then _P2_L_R = _P2_L_R + 0.07 if _P2_L_R > _P0_L_R then _P2_L_R = _P2_L_R - 0.07 if _P3_U_D < _P0_U_D then _P3_U_D = _P3_U_D + 0.10 if _P3_U_D > _P0_U_D then _P3_U_D = _P3_U_D - 0.10 if _P3_L_R < _P0_L_R then _P3_L_R = _P3_L_R + 0.10 if _P3_L_R > _P0_L_R then _P3_L_R = _P3_L_R - 0.10 if _P4_U_D < _P0_U_D then _P4_U_D = _P4_U_D + 0.15 if _P4_U_D > _P0_U_D then _P4_U_D = _P4_U_D - 0.15 if _P4_L_R < _P0_L_R then _P4_L_R = _P4_L_R + 0.15 if _P4_L_R > _P0_L_R then _P4_L_R = _P4_L_R - 0.15 if collision(player0,player1) then goto Game_Over k = 0 if player0x < 16 then player0x = 139 : k = (rand&3) : bally = 47 : ballx = rand : player1x = 29 : player1y = 79 : player2x = 139 : player2y = 79 : player3x = 29 : player3y = 33 if player0x > 138 then player0x = 16 : k = (rand&3) : bally = 47 : ballx = rand if player0y > 90 then player0y = 10 : k = (rand&3) : bally = 47 : ballx = rand if player0y < 10 then player0y = 90 : k = (rand&3) : bally = 47 : ballx = rand if k = 1 then goto Screen_1 : k = 0 if k = 2 then goto Screen_2 : k = 0 if k = 3 then goto Screen_3 : k = 0 if joy0right then _P0_L_R = _P0_L_R + 0.30 : n = 11 if joy0left then _P0_L_R = _P0_L_R - 0.30 : n = 11 if joy0up then _P0_U_D = _P0_U_D + 0.30 : n = 11 if joy0down then _P0_U_D = _P0_U_D - 0.30 : n = 11 if collision(player0,playfield) && joy0right then player0x = player0x - 3 if collision(player0,playfield) && joy0left then player0x = player0x + 3 if collision(player0,playfield) && joy0up then player0y = player0y - 3 if collision(player0,playfield) && joy0down then player0y = player0y + 3 if ballx < 16 then bally = 255 if ballx > 138 then bally = 255 if collision(player0,ball) then bally = 255 : score = score + 40 : p = 11 : player1y = 255 : player2y = 255 : player3y = 255 : player4y = 255 q = q + 0 if player1y = 255 then COLUPF = $0E : COLUBK = $0E : q = q + 1 if q > 4 then COLUPF = $20 : COLUBK = $00 if n > 0 then AUDV0 = 8 : AUDC0 = 2 : AUDF0 = 18 : n = n - 1: if n = 0 then AUDV0 = 0 if p > 0 then AUDV0 = 8 : AUDC0 = 3 : AUDF0 = 23 : p = p - 1: if n = 0 then AUDV0 = 0 goto Level_1 Game_Over playfield: ................ ................ ................ ................ ................ ..........XXX... ............XX.. ................ .............XXX ............XXXX ...........XXXX. end AUDV0 = 0 : AUDC0 = 0 : AUDF0 = 0 gameover COLUPF = $0E COLUBK = $00 player0x = 100 player0y = 100 player1x = 100 player1y = 100 player2x = 100 player2y = 100 player3x = 100 player3y = 100 player4x = 100 player4y = 100 drawscreen if joy0fire || joy1fire then reboot goto gameover Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 15, 2013 Share Posted June 15, 2013 Here is a slightly fixed up version of what you posted: rabbit_title_screen_troubles_2013y_06m_15d_1338t.bas rabbit_title_screen_troubles_2013y_06m_15d_1338t.bin I wasn't sure if you wanted to waste some variables on collision detection, so I basically left it the way it was with a couple of changes. Remember, you can just use this .bas file. You don't need to edit another .bas file to match. Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 (edited) Cheers once again, Random =) I looked over your changes, they'r genius. But I have 1 more small question. I added a new room and set it up as the rest. if k = 4 then playfield: "imagine layout here" And changed k = (rand&3) : if !k then k = 1 into k = (rand&4) : if !k then k = 1 Now it switches only between the first room and this room, how come? Edited June 15, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 15, 2013 Share Posted June 15, 2013 (edited) Cheers once again, Random =) I looked over your changes, they'r genius. But I have 1 more small question. I added a new room and set it up as the rest. if k = 4 then playfield: "imagine layout here" And changed k = (rand&3) : if !k then k = 1 into k = (rand&4) : if !k then k = 1 Now it switches only between the first room and this room, how come? I did explain that to you rand hgfedcba & 4 00001000 = 0000d000 d can only be 1 or 0 so the only posibile results are 00000000 = 0 if d = 0 00001000 = 4 if d = 1 Edited June 15, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 (edited) Ahh, now I get it. 4 is not possible. But if I get it, 7 is? Edited June 15, 2013 by Rabbit 2600 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 15, 2013 Share Posted June 15, 2013 well then just accept that rand & 3 can be any number in the range 0, 1, 2, 3 rand & 4 can only be 0 or 4 Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 And rand & 7 is the range between 0, 1 , 2 , 3 , 4 , 5 , 6 and 7 =) If I wanted more the next number would be 15 Quote Link to comment Share on other sites More sharing options...
bogax Posted June 15, 2013 Share Posted June 15, 2013 (edited) And rand & 7 is the range between 0, 1 , 2 , 3 , 4 , 5 , 6 and 7 =) If I wanted more the next number would be 15 correct the way RT and theloon do it is to add two (but it may take more) ranges that get you something like what you want but it won't be purely random any more, some numbers will be more likely than others. you could do (rand & 3) + (rand & 1) to get one of 0, 1, 2, 3, 4 Edited June 15, 2013 by bogax Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted June 15, 2013 Author Share Posted June 15, 2013 Mhm! Thanks for your patience bogax. I'm a bit thick-headed at times and not really a fast learner. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted June 16, 2013 Share Posted June 16, 2013 There is a chart here that you can use whenever you can't remember: randomterrain.com/atari-2600-memories-batari-basic-commands.html#rand Do you see the box on the right with "Did You Know?" at the top? All you have to do is look at that box and it will remind you that 1, 3, 7, 15, 31, 63, 127 are the magic numbers to use. 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.