News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Dagger

CPC BASIC 3

Started by Dagger, 23:17, 12 January 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Dagger

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
Life's a bitch. You marry one or two then you die !

roudoudou

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
My pronouns are RASM and ACE

Dagger

The Error is in single arrays as well. :(

Life's a bitch. You marry one or two then you die !

AMSDOS

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.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Dagger

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 .
Life's a bitch. You marry one or two then you die !

SRS

#5
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)


Dagger

#6
Ok, thank you. I will give that a try. That does look good  :D
Life's a bitch. You marry one or two then you die !

Powered by SMFPacks Menu Editor Mod