Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array initialization bug (*solved*)
#1
My next ZX BASIC game requires a lookup table for variable sized data.

The simplest solution would be something like this:

Code:
data1:
    asm
        defb 0,1,2,3,4,5
    end asm
data2:
    asm
        defb 6,7,8
    end asm
data3:
    asm
        defb 9,10,11,12
    end asm

DIM array(1 TO 3) AS UINTEGER = { @data1, @data2, @data3 }

But compiling this program using latest version of ZX BASIC (incorrectly) produces the following error messages:

Code:
prog.bas:14: Initializer expression is not constant.
prog.bas:14: Initializer expression is not constant.
prog.bas:14: Initializer expression is not constant.

Another alternative would be declaring the lookup table directly in ASM, but ZX BASIC doesn't support mapping arrays to memory addresses either:

Code:
DIM array(1 TO 3) AS UINTEGER AT @data

For now, I'm implementing everything "manually" instead of using ZX BASIC arrays. But it would be nice if this problem could be fixed in future releases! Smile
Reply
#2
Definitely this is a bug! :oops:
Thanks for reporting.
These days I'm (finally) fixing this and other bugs reported here.
Reply
#3
Thank you!!!
Reply
#4
Just wondering if there has been any progress on this bug?

I'm asking because other bugs I reported recently have easy (efficient) workarounds, this one doesn't...
Reply
#5
einar Wrote:Just wondering if there has been any progress on this bug?

I'm asking because other bugs I reported recently have easy (efficient) workarounds, this one doesn't...
OMG I forgot about it completely :!:

This one was hard one to fix... And I'm thinking of make another compiler revamp (been QUITE busy since last year).
I need to write the roadmap on the zxbasic.net (wiki) site.
Reply
#6
Thanks for the feedback!
Reply
#7
This still looks like its an issue, any chance it can be fixed?

Or is there a way around this?

Thanks
Reply
#8
Just released ZX Basic 1.5.1 (had an almost sabbatic year in 2016, really needed it)

Will try to address this in ZXBasic 1.5.3 but it's a tough one.
Also, which ZX Basic version are you using? on which platform? (Windows, Linux, etc?)
Reply
#9
Okay, after *a lot* of work, it's finally done.
Please, download version 1.6.10 and try to do it.

Also you can now use ON (expression) GOTO label1, label2, ... (up to 255 labels). Also ON ... GOSUB.
example:
Code:
ON RND * 4 GOTO label0, label1, label2

PRINT "3 or higher!"
END

label0:
   PRINT "it was a 0"
   END

label1:
   PRINT "it was a 1"
   END

label2:
   PRINT "it was a 2"

(expression) can be any numerical expression (it will be converted to byte). If the result is 0, it will jump to the 1st label, 1, for the 2nd, etc...
If the result pass beyond the last label, no action is taken (the program continues normally).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)