Jump to content


7800Basic and Arrays

7800 BASIC Array variable data length

3 replies to this topic

#1 Lavalamp OFFLINE  


    Chopper Commander

  • 119 posts
  • Location:Wellington, New Zealand.

Posted Thu Oct 4, 2018 12:35 PM

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?




Variable Arrays

Regular 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.

Using 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

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...




#2 SmittyB ONLINE  



  • 287 posts

Posted Thu Oct 4, 2018 1:11 PM

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.randomter...basic.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!

#3 Lavalamp OFFLINE  


    Chopper Commander

  • Topic Starter
  • 119 posts
  • Location:Wellington, New Zealand.

Posted Thu Oct 4, 2018 1:24 PM

thanks SmittyB that makes sense, so the below gives me five instances of enemyX?

dim enemyX[0] = var1
dim lives     = var6

Edited by Lavalamp, Thu Oct 4, 2018 1:25 PM.

#4 SmittyB ONLINE  



  • 287 posts

Posted Thu Oct 4, 2018 1:43 PM

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.

Also tagged with one or more of these keywords: 7800, BASIC, Array, variable, data, length

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users