Snestalgia Posted December 9, 2015 Share Posted December 9, 2015 So every time I walk through a door, I want to be taken to a random play field. There are 8 play fields in the game and they are named "1","2","3","4","5","6","7","8" This section of my code looks like this:if player0x>160 then a=(rand/32)+1 if a=1 then gosub 1 if a=2 then gosub 2 if a=3 then gosub 3 if a=4 then gosub 4 if a=5 then gosub 5 if a=6 then gosub 6 if a=7 then gosub 7 if a=8 then gosub 8 Is there any way to simplify this to save space? I know there has to be a way but I can't get anything to work. Thank you for your help. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 9, 2015 Share Posted December 9, 2015 Looks like you are using batari Basic. You might want to post future questions in the batari Basic forum: atariage.com/forums/forum/65-batari-basic/ Seems like you'd want to use on…gosub. dim _PF_Jump = a if player0x > 160 then _PF_Jump = (rand/32) on _PF_Jump gosub __PF0 __PF1 __PF2 __PF3 __PF4 __PF5 __PF6 __PF7 . . . __PF0 blah blah blah return __PF1 blah blah blah return __PF2 blah blah blah return __PF3 blah blah blah return __PF4 blah blah blah return __PF5 blah blah blah return __PF6 blah blah blah return __PF7 blah blah blah return You could also use on…goto instead and have the places you jump to jump back to a label. dim _PF_Jump = a if player0x > 160 then _PF_Jump = (rand/32) on _PF_Jump goto __PF0 __PF1 __PF2 __PF3 __PF4 __PF5 __PF6 __PF7 __PF_Jump_Back . . . __PF0 blah blah blah goto __PF_Jump_Back __PF1 blah blah blah goto __PF_Jump_Back __PF2 blah blah blah goto __PF_Jump_Back __PF3 blah blah blah goto __PF_Jump_Back __PF4 blah blah blah goto __PF_Jump_Back __PF5 blah blah blah goto __PF_Jump_Back __PF6 blah blah blah goto __PF_Jump_Back __PF7 blah blah blah goto __PF_Jump_Back Quote Link to comment Share on other sites More sharing options...
Snestalgia Posted December 9, 2015 Author Share Posted December 9, 2015 Looks like you are using batari Basic. You might want to post future questions in the batari Basic forum: atariage.com/forums/forum/65-batari-basic/ Seems like you'd want to use on…gosub. dim _PF_Jump = a if player0x > 160 then _PF_Jump = (rand/32) on _PF_Jump gosub __PF0 __PF1 __PF2 __PF3 __PF4 __PF5 __PF6 __PF7 . . . __PF0 blah blah blah return __PF1 blah blah blah return __PF2 blah blah blah return __PF3 blah blah blah return __PF4 blah blah blah return __PF5 blah blah blah return __PF6 blah blah blah return __PF7 blah blah blah return You could also use on…goto instead and have the places you jump to jump back to a label. dim _PF_Jump = a if player0x > 160 then _PF_Jump = (rand/32) on _PF_Jump goto __PF0 __PF1 __PF2 __PF3 __PF4 __PF5 __PF6 __PF7 __PF_Jump_Back . . . __PF0 blah blah blah goto __PF_Jump_Back __PF1 blah blah blah goto __PF_Jump_Back __PF2 blah blah blah goto __PF_Jump_Back __PF3 blah blah blah goto __PF_Jump_Back __PF4 blah blah blah goto __PF_Jump_Back __PF5 blah blah blah goto __PF_Jump_Back __PF6 blah blah blah goto __PF_Jump_Back __PF7 blah blah blah goto __PF_Jump_Back Thanks for the help. Ok so I did all that and hit compile, and I get an error with this line in red on _PF_Jump gosub __PF0 __PF1 __PF2 __PF3 __PF4 __PF5 __PF6 __PF7 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 9, 2015 Share Posted December 9, 2015 Did you create the labels and did you use DIM?randomterrain.com/atari-2600-memories-batari-basic-commands.html#dim Quote Link to comment Share on other sites More sharing options...
Snestalgia Posted December 10, 2015 Author Share Posted December 10, 2015 Did you create the labels and did you use DIM? randomterrain.com/atari-2600-memories-batari-basic-commands.html#dim Yes, I did everything you said and its still not working. Still won't compile Is there any other way? like for example: a=(rand/32)+1 gosub a I know this won't work, but is there anything similar? Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted December 10, 2015 Share Posted December 10, 2015 You could always attach the code you said wasn't working and I could see what is messed up. Quote Link to comment Share on other sites More sharing options...
RevEng Posted December 26, 2015 Share Posted December 26, 2015 on...gosub isn't part of the bB 1.0 offered at bataribasic.com. If you're using that one, do yourself a favor and upgrade using RT's getting started instructions. 1 Quote Link to comment Share on other sites More sharing options...
bogax Posted December 30, 2015 Share Posted December 30, 2015 you can create your own version of on gosub and on goto with just a little assembly asm jmp (temp5) end will jump to whatever location you specify in variables temp5, temp6 with the lo byte of the location in temp5 and the hi byte in temp6 Bb prepends a "." to labels, "my_label" in Bb becomes ".my_label" in the assembly labels are 16 bit but you can specify the lo byte, "<.my_label" or the hi byte, ">.my_label" you can't generally use "<.my_label" in Bb but you can in a constant declaration or a data statement so const ml_lo = <.my_label const ml_hi = >.my_label temp5 = ml_lo : temp6 = ml_hi asm jmp (temp5) end works in Bb and is sort of like goto my_label for on a gosub it would be something like set optimization noinlinedata if player0x > 160 then a = (rand/32) gosub on_a on_a temp5 = jump_table_lo[a] : temp6 = jump_table_hi[a] asm jmp (temp5) end data jump_table_lo <.PF0, <.PF1, <.PF2, <.PF3, <.PF4, <.PF5, <.PF6, <.PF7 end data jump_table_hi >.PF0, >.PF1, >.PF2, >.PF3, >.PF4, >.PF5, >.PF6, >.PF7 end PF0 rem some stuff return PF1 rem some stuff return PF2 rem some stuff return PF3 rem some stuff return PF4 rem some stuff return PF5 rem some stuff return PF6 rem some stuff return PF7 rem some stuff return of course it's more trouble than a simple on gosub and it uses 3 more bytes (provided you use the noinlinedata optimization which saves you three bytes per data statement. Bb inserts a hidden goto to go past the data whether it needs to or not, of course you have to be sure you have no in line data) on gosub is limited to what you can fit on a single line while data statements can have up to 256 items and span multiple lines I second the "post your code" suggestion I'd suggest that you use rand16 if you can affored the extra byte of ram since you've got 8 things you're choosing amongst and 8 is a power of 2 and if you're zero based you can lose the "+ 1" so you can do this instead and save a few bytes a = rand & 7 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.