Lavalamp #1 Posted October 4, 2018 Hi, I'm having issues with implementing arrays in 7800Basic, the online manual appears to have an example that makes no sense to me, it doesn't show how to declare an Array? http://www.randomterrain.com/7800basic.html#dimensioning_variable_names Variable ArraysRegular variables can be accessed as arrays in 7800basic. Doing so will access memory locations next to the variable in question. The following sets variables "a", "b", and "c" to 0. a[0]=0 a[1]=0 a[2]=0Using array notation will allow you to loop through elements without a lot of duplicated code, providing you've used dim to place the elements side by side in memory. I assume to declare its like my example below? dim enemyX[0] = var1 dim enemyX[1] = var2 dim enemyX[2] = var3 this means I can loop through them like this? for temp1 = 0 to 2 if enemyX[temp1] >160 then enemyX[temp1] = 0 next Also...getting the _length of data appears to be unclear to me, I get an error about it been before the data statement or something... Quote Share this post Link to post Share on other sites
+SmittyB #2 Posted October 4, 2018 You don't need to define each variable of an array. What actually happens is that when you say for example 'enemyX[5] = 100' it's really just taking the address of enemyX and adding 5 to it. It's up to you to make sure you're not going outside of the range you expect, for example you can start a 32 byte array at 'var16', then because the next 32 bytes are going to need to be free for the array you dim your next variable at 'var48', but there's nothing stopping you changing the value at array[56] which would be outside the space you've left free and you can easily overwrite other data. I've not used the dataname_length constant myself so I don't know what 7800BASIC does to define it, but according to http://www.randomterrain.com/7800basic.html#datayou need to make sure you define your data first. I'm guessing when it compiles it tries to do all that on the first pass. Sorry if this makes no sense, I've had a little too much wine. Don't drink and code! Quote Share this post Link to post Share on other sites
Lavalamp #3 Posted October 4, 2018 (edited) thanks SmittyB that makes sense, so the below gives me five instances of enemyX? dim enemyX[0] = var1 dim lives = var6 Edited October 4, 2018 by Lavalamp Quote Share this post Link to post Share on other sites
+SmittyB #4 Posted October 4, 2018 Technically you can always reference enemyX[0] to enemyX[255], but yes if you know for certain you will only ever reference 0 to 5 then that's fine. Any reference to 'enemyX[6]' would be the same as referencing 'lives'. Also don't forget that var0 is valid. Quote Share this post Link to post Share on other sites
Dalta #5 Posted February 4, 2019 Anyone have a solution for implementing an array of bullets? In the sample code I've seen, usually a bullet sprite is plotted only while fire is held down, however I'd like for a bullet to be created when fire is pressed, and only disappear when it hits something or after a time limit. Normally to do this I would create an array of bullets and each time the fire button is pressed, add an item to that array, then when it's time to draw the screen, just do a for loop and plot each bullet before moving to the next. However, in 7800basic I can't seem to find a workaround, I think I've managed to create an array by declaring 'player_bullets[0]' as var0, with the intention of reserving 10 spaces, up to var9, for the players bullets, but I can't seem to even read an array element using a variable, i.e. I have a counter for the amount of bullets called 'bullcon', but referencing player_bullets[bullcon] returns an error. Can anyone help? Thank you Quote Share this post Link to post Share on other sites
+SmittyB #6 Posted February 4, 2019 What you want to do is something like rem Define a variable representing the start of the array dim player_bullets = var0 dim bullcon = var10 for bullcon = 0 to 9 player_bullets[bullcon] = result_of_some_function next 2 Quote Share this post Link to post Share on other sites