+Muddyfunster Posted June 2, 2020 Share Posted June 2, 2020 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! 1 Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 2, 2020 Share Posted June 2, 2020 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) 2 Quote Link to comment Share on other sites More sharing options...
+Muddyfunster Posted June 2, 2020 Author Share Posted June 2, 2020 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 Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 2, 2020 Share Posted June 2, 2020 I'm not sure. Conceptually it should work... maybe paste the source as you have now, so I can dig in. 1 Quote Link to comment Share on other sites More sharing options...
+Muddyfunster Posted June 2, 2020 Author Share Posted June 2, 2020 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 Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 2, 2020 Share Posted June 2, 2020 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 1 Quote Link to comment Share on other sites More sharing options...
+Muddyfunster Posted June 2, 2020 Author Share Posted June 2, 2020 32 minutes ago, RevEng said: ...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]") Yes indeed Thanks again @RevEng Quote Link to comment Share on other sites More sharing options...
RevEng Posted June 2, 2020 Share Posted June 2, 2020 Excellent. I've updated my local copy of the 7800basic manual, with comments about array types not being useful directly in statements. 4 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.