Jump to content
IGNORED

Question on arrays


Recommended Posts

I've been tightening and scaling up some of the engine features in EXO and I wanted to plot a sprite based on which number in the array is called, so I could remove some of my early brute force code.

 

So for the test example I declare a bunch of set up variables and then I set up a simple loop to plot them :

 

 set romsize 48k
 set tallsprite on
 set doublewide on
 set tv ntsc
 set zoneheight 8

 dim rocket_x = $2224.$222E
 dim rocket_y = $2238.$2242
 dim rocket_max = var29

 incgraphic gfx/rocket.png

  P0C1=$08 ; med
  P0C2=$0c ; light
  P0C3=$04 ; dark

 rocket_x[1] = 75 : rocket_y[1] = 56
 rocket_x[2] = 45 : rocket_y[2] = 56
 rocket_max = 2

mainloop
 clearscreen
 for a = 1 to rocket_max
 plotsprite rocket 0 rocket_x[rocket_max] rocket_y[rocket_max] 0 2
 ;plotsprite rocket 0 rocket_x rocket_y 0 2
 next a

 drawscreen

 goto mainloop

I'm trying to plot the sprite called rocket, using palette #0 and using the rocket_x and rocket_y co-ordinates in the array but the code will not compile.

 

rocket_x and rocket_y are 8.8 variables each with 10 bytes space allocated (so in my theoretical thinking I can safely have rocketmax = 9 before I run out of space and have to extend the array)

 

Am I defining these variables incorrectly as I cannot get the code to compile unless I remove the [] condition (and it then doesn't do what it is intended).

 

I suspect I'm in the "can't see the wood for the trees" mode of thinking.

 

Any guidance or advice would be appreciated!

 

 

 

  • Like 1
Link to comment
Share on other sites

You have it mostly right, but have assumed the parser is more capable than it is. :) For pretty much anything other than variable assignments, arrays don't work as arguments. (true for bB as well) The easiest work-around is to assign your array indexes to a temporary location first.

 

e.g.

mytempx = rocket_x[rocket_max]

mytempy = rocket_y[rocket_max]

plotsprite rocket 0 mytempx mytempy 0 2

 

Avoid using the system temp# variables for this purpose, because plotsprite will probably obliterate them before using them. I always dim a few "mytemp" variables for this sort of purpose. (also handy for generalized subroutines that can operate on different game objects)

  • Like 2
Link to comment
Share on other sites

Gah! thanks @RevEng

 

I can compile but the sprite just sits in the corner of the screen. It's as though the plotsprite isn't picking up the co-ords from the array, even using the temp variables :

 

I added mytempx and mytempy as 8.8 vars and drop the array values in before passing that to plotsprite.

 

 for a = 1 to rocket_max
 mytempx = rocket_x[rocket_max]
 mytempy = rocket_y[rocket_max]
 plotsprite rocket 0 mytempx mytempy 0 2
 next a

 

Link to comment
Share on other sites

Thanks,

 

source below :

 

 set romsize 48k
 set tallsprite on
 set doublewide on
 set tv ntsc
 set zoneheight 8

 dim rocket_x = $2224.$222E
 dim rocket_y = $2238.$2242
 dim rocket_max = var1
 dim mytempx = b.c 
 dim mytempy = d.e 


 incgraphic gfx/rocket.png

  P0C1=$08 ; med
  P0C2=$0c ; light
  P0C3=$04 ; dark

 rocket_x[1] = 75 : rocket_y[1] = 56
 rocket_x[2] = 45 : rocket_y[2] = 56
 rocket_max = 2

mainloop
 clearscreen
 for a = 1 to rocket_max
 mytempx = rocket_x[rocket_max]
 mytempy = rocket_y[rocket_max]
 plotsprite rocket 0 mytempx mytempy 0 2
 
  next a

 drawscreen

 goto mainloop

 

Link to comment
Share on other sites

Ok, it looks like 8.8 assignments from arrays doesn't do what you're wanting, since arrays are strictly byte sized things.

 

If you change this...

 dim mytempx = b.c 
 dim mytempy = d.e 

to...

 dim mytempx = b
 dim mytempy = d

...then your code will work as expected.  (well, I think you wanted to use "mytempx = rocket_x[a]" instead of "mytempx = rocket_x[rocket_max]")

 

If you still want to treat those temps as 8.8 in certain circumstances, then you can dim another view of them like that...

dim mytempx8 = b.c

  • Like 1
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...