CPCWiki forum

General Category => Programming => Topic started by: Dagger on 23:17, 12 January 19

Title: CPC BASIC 3
Post by: Dagger on 23:17, 12 January 19
Is there a problem with arrays using CPC basic 3 ?. If I run the following code under CPC Basic 3 it does not return the correct value. Under Winape it works as it should


5 CLS: DIM XY%(40,24)
10 B%=1
15 FOR A%=1 TO 40:XY%(A%,B%)=200:NEXT
20 B%=B%+1:IF B%<25 THEN GOTO 15
40 LOCATE 10,12:PRINT XY%(11,10)

Win Ape returns 200 which is correct but under CPC Basic 3 once you use values for the array greater than 10,10 it returns the value 0
Title: Re: CPC BASIC 3
Post by: roudoudou on 23:37, 12 January 19
DIM support is simplified (i guess)I saw in the documentation you can specify lenght of an array of strings with DIM n$(10)*15 which is not a Locomotive syntax
Title: Re: CPC BASIC 3
Post by: Dagger on 00:38, 13 January 19
The Error is in single arrays as well. :(

Title: Re: CPC BASIC 3
Post by: AMSDOS on 03:18, 13 January 19
The error is occurring because a constant area of the array is being told straight out to display what's there, which becomes complicated when the code is translated into Machine Code. To fix this you can put the coordinates of the array into some variables, so:


10 b%=1:c%=11:d%=10
40 LOCATE 10,12:PRINT xy%(c%,d%)


will work with CPC BASIC 3.
Title: Re: CPC BASIC 3
Post by: Dagger on 11:48, 13 January 19
Thank you but that would lead to an extremely lot of code to access the data :( Eg I need to create a screen array, as 85% of the screen has a graphic .
Title: Re: CPC BASIC 3
Post by: SRS on 21:41, 13 January 19
Well, "The indexes specified in the declaration of a table must be constant expressions, you can not use variables in them. For example DIM a (10* 3) is correct, but it is not DIM a(10*n)."
DIM is different form LOCO(more like C) - so this works for me:

5 CLS:DIM XY%(40*24)
10 B%=1
15 FOR A%=1 TO 40:XY%(A%*B%)=200:NEXT
20 B%=B%+1:IF B%<25 THEN GOTO 15
40 LOCATE 10,12:PRINT XY%(11*10)
Faster:
5 CLS:DIM XY%(40*24)
15 FOR A!=1 TO 40*24:XY%(A!)=200:NEXT
40 LOCATE 10,12:PRINT XY%(11*10)
Title: Re: CPC BASIC 3
Post by: Dagger on 22:43, 13 January 19
Ok, thank you. I will give that a try. That does look good  :D
Powered by SMFPacks Menu Editor Mod