Jump to content
IGNORED

7800Basic and Arrays


Lavalamp

Recommended Posts

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

a[0]=0
a[1]=0
a[2]=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
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...

 

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 4 months later...

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...