If anyone can help me with this, I would most appreciate it...
Hi, I am slowly using my marbles due to DATA statements being (I think) totally unreliable. Let's take this code... should be easy no? A housekeeping statement in the first line, then declaring the string 'team' as an array of 48 names (0-47... Go through the data, read, and print the team name...
THIS IS NOT ALWAYS WORKING FOR ME... does it read? I can't tell as there are no apparent errors anywhere... This code I have tested on its own in a new blank basic file... still no go. I have the latest updates, and have even tried this on TWO different computers (using Spectrum and C64 emulation), just to be sure. I have been struggling with data files for two days now (apart from my DWORD foul)
I am having so much problems with these variables that I am resorting to naming the other important strings , such as fixtures or player names, specifically... ex... ply_name(1)="DelPiero" , ply_name(2)="Chiellini"...
CLS BLACK : PAPER BLACK : COLOR BORDER BLACK : PEN WHITE
'
DIM team AS STRING(48) ' (DECLARE 48 TEAMS AS STRING DATA)
FOR i=0 TO 47 ' (START OF FOR NEXT LOOP TO READ THE DATA)
READ team(i) (READ THE TEAM NAME FROM THE DATA)
PRINT team(i) (PRINT THE TEAM NAME)
NEXT (END OF LOOP)
'
DATA "AFC Fylde","Accrington St","Aldershot","Altrincham","Barnet","Barrow"
DATA "Boston Utd","Bradford C.","Braintree","Bromley","Carlisle","Cheltenham"
DATA "Chesterfield","Colchester","Crewe","Dag. & Red.","Doncaster","Eastleigh"
DATA "Ebbsfleet","Fleetwood","Forest Green","Gateshead","Gillingham FC","Grimsby"
DATA "Halifax","Harrogate","Hartlepool","Maidenhead","Milton Keynes","Morecambe"
DATA "Newport","Notts County","Oldham","Port Vale","Rochdale","Salford"
DATA "Solihull Moors","Southend Utd","Sutton","Swindon","Tamworth","Tranmere"
DATA "Walsall","Wealdstone","Wimbledon","Woking","Yeovil","York City"
PRINT "Does not get to this point..." (THE PROGRAM DOES NOT ALWAYS ARRIVE HERE)
WAIT KEY
------------------------------------------
HOWEVER, if I change the code to this, it WILL sometimes work... of course all the rest of the data for other variables will be totally random.
DIM team AS STRING(16)
FOR i=0 TO 15
READ team(i)
PRINT team(i)
NEXT
DATA read problems... (FIXED!)
-
- Posts: 6
- Joined: Mon Dec 30, 2024 1:54 pm
DATA read problems... (FIXED!)
Last edited by Grillomalta on Tue Dec 31, 2024 6:20 pm, edited 1 time in total.
-
- Site Admin
- Posts: 178
- Joined: Fri Oct 06, 2023 8:25 pm
Re: DATA read problems...
Hi Grilllomalta!
Let me know.
This is really weird, because I copied and pasted the code you wrote here and it works for me, both on the Commodore 64, the ZX Spectrum and also the Amstrad CPC 664:Grillomalta wrote: ↑Tue Dec 31, 2024 10:11 am Hi, I am slowly using my marbles due to DATA statements being (I think) totally unreliable. Let's take this code... should be easy no? A housekeeping statement in the first line, then declaring the string 'team' as an array of 48 names (0-47... Go through the data, read, and print the team name...
THIS IS NOT WORKING FOR ME...
Ok, but always keep in mind that the resources for managing dynamic strings (that is: those that are not in DATA) are limited in number. At most you can manage 256 at the same time. If you have decided to use DATA, it is better to use them as a sort of "mass memory", keeping in the arrays only the things that you strictly need. In this way, you optimize both the space used by the strings and the space used by the arrays, and guarantee an optimal occupation of space. To do this you can use the RESTORE command, which is able to index the READ to the DATA you need.Grillomalta wrote: ↑Tue Dec 31, 2024 10:11 am I am having so much problems with these variables that I am resorting to naming the other important strings , such as fixtures or player names, specifically... ex... ply_name(1)="DelPiero" , ply_name(2)="Chiellini"...
If I may, this syntax is a bit old-fashioned. You can use this one, which is more similar to modern BASIC:Grillomalta wrote: ↑Tue Dec 31, 2024 10:11 am DIM team AS STRING(48) ' (DECLARE 48 TEAMS AS STRING DATA)
Code: Select all
DIM team(48) AS STRING
-
- Posts: 6
- Joined: Mon Dec 30, 2024 1:54 pm
Re: DATA read problems...
Thank you for your prompt answer... Still not working for me... If I add an input after that line, IF the program continues (and remember, what I sent is on a new basic program)
Doesn't work on my larger app ... The most I can get to obtain a reliable continuation is 24 teams, though I have to reduce the fixtures.
Here is a mock-up before optimization. Using direct gotos before writing it in modern mode.
48 teams (duplicated just for checking).
Will not even arrive at the fixtures beyond fixt(10) ...
CLS BLACK : PAPER BLACK : COLOR BORDER BLACK : PEN WHITE
'
DIM team(48) AS STRING
DIM fixt(15) AS STRING
DIM plyname(17) AS STRING
DIM day(15) AS INTEGER
DIM result_string(15) AS STRING
DIM xteam(16) AS STRING
DIM vb(16) AS STRING , vc(16) AS STRING
DIM ply_age(17) AS INTEGER , ply_skl(17) AS INTEGER
DIM ply_fit(17) AS INTEGER , ply_dev(17) AS INTEGER
DIM ply_gls(17) AS INTEGER , ply_yel(17) AS INTEGER , ply_red(17) AS INTEGER
DIM won(16) AS INTEGER , drew(16) AS INTEGER , lost(16) AS INTEGER
DIM scored(16) AS INTEGER , conceded(16) AS INTEGER , points(16) AS INTEGER
DIM x_won(16) AS INTEGER , x_drew(16) AS INTEGER
DIM x_lost(16) AS INTEGER , x_scored(16) AS INTEGER
DIM x_conceded(16) AS INTEGER , x_points(16) AS INTEGER
DIM b(16) AS INTEGER , c(16) AS INTEGER
DIM opponent_goalie(16) AS INTEGER
DIM opponent_defence(16) AS INTEGER
DIM opponent_midfield(16) AS INTEGER
DIM opponent_attack(16) AS INTEGER
FOR i=0 TO 16
ply_age(i)=16+INT(RND(14))
ply_skl(i)=6+INT(RND(5))
ply_fit(i)=6+INT(RND(5))
ply_dev(i)=6+INT(RND(5))
ply_gls(i)=6+INT(RND(5))
NEXT
z1=0 : z2=0 : cb=500000 : gu=1 : day=1 : i=0
DO
READ team(i)
PRINT i,team(i)
INC i
IF i=48 THEN EXIT
LOOP
'
DATA "Aldershot ","Barnet ","Barrow "
DATA "Bradford C. ","Bromley ","Carlisle Utd"
DATA "Colchester ","Crewe Alex ","Doncaster "
DATA "Fleetwood ","Gateshead ","Grimsby "
DATA "Halifax ","Hartlepool ","Milton K. "
DATA "Newport ","Oldham Ath. ","Rochdale "
DATA "Southend Utd","Swindon ","Tranmere R. "
DATA "Walsall ","Wimbledon ","York City "
DATA "Aldershot ","Barnet ","Barrow "
DATA "Bradford C. ","Bromley ","Carlisle Utd"
DATA "Colchester ","Crewe Alex ","Doncaster "
DATA "Fleetwood ","Gateshead ","Grimsby "
DATA "Halifax ","Hartlepool ","Milton K. "
DATA "Newport ","Oldham Ath. ","Rochdale "
DATA "Southend Utd","Swindon ","Tranmere R. "
DATA "Walsall ","Wimbledon ","York City "
WAIT 1000 MS : COLOR BORDER GREEN : CLS BLACK
PEN YELLOW : LOCATE 0,0 : i=0
DO
READ fixt(i)
PRINT fixt(i)
INC i
IF i=15 THEN EXIT
LOOP
DATA"01030408051306110715121014021609"
DATA"01140803090610071104121613021505"
DATA"01080215031104090510061214131607"
DATA"01110516070608140903100212041513"
DATA"01090312040706050811131014151602"
DATA"01120206050407030908101511141316"
DATA"01070305040206130812110914101615"
DATA"01050203070809141016121113041506"
DATA"01020313041506100805091211071614"
DATA"01130208051107091004141215031606"
DATA"01150310041606140813090511021207"
DATA"01100209051206041311140715081603"
DATA"01160306041407050810091311151202"
DATA"01060207040310111312140515091608"
DATA"01040314050207130806091011161215"
WAIT 1000 MS
COLOR BORDER YELLOW
CLS BLACK
PEN PURPLE
LOCATE 0,0
i=0
DO
READ plyname(i)
PRINT plyname(i)
INC i
IF i=17 THEN EXIT
LOOP
DATA "(G) Anderson"
DATA "(G) Martin "
DATA "(D) Rogers "
DATA "(D) Kensdale"
DATA "(D) Ralph"
DATA "(D) Ashley"
DATA "(D) Woodman"
DATA "(D) Taylor"
DATA "(M) Bridge"
DATA "(M) Coker"
DATA "(M) Thomas"
DATA "(M) James"
DATA "(M) Blake"
DATA "(M) Crowther"
DATA "(F) Rose"
DATA "(F) Cardwell"
DATA "(F) Powell"
WAIT 1000 MS
CLS BLUE
INK YELLOW:LOCATE 0,8:CENTRE "GRFM2025 Retro 8-bit"
INK GREEN : LOCATE 0,10 : CENTRE "by Chris Grillo"
INK CYAN : LOCATE 0,17 : CENTRE "LOADING."
WAIT 2000 MS
i=0
CLS BLACK
PEN YELLOW
LOCATE 0,0
PRINT "Choose a team to manage"
PRINT
FOR i=0 TO 15
IF i MOD 2 THEN
PEN WHITE
ELSE
PEN CYAN
ENDIF
PRINT i+1,team(i),i+2,team(i+1)
NEXT
PEN YELLOW
PRINT
INPUT "Your choice " ; k
IF k<1 OR k>16 THEN k=1
PEN RED
PRINT
PRINT "You are hired by ";team(k-1)
team(1)=team(k-1)
WAIT 1000 MS
k=0
mainmenu:
CLS BLACK
COLOR BORDER BLUE
LOCATE 0,0
PEN YELLOW
PRINT
PRINT " Main Desk : " ; team(1)
PRINT
PEN WHITE
PRINT " 1. Players"
PRINT
PRINT " 2. League Table"
PRINT
PRINT " 3. Total Fixtures"
PRINT
PRINT " 4. Opponent Skill"
PEN CYAN
PRINT
PRINT " 5. Transfer List"
PRINT
PEN YELLOW
PRINT " 6. Finances"
PRINT
PRINT " 7. Stadium"
PRINT
PEN GREEN
PRINT " 8. Next Match"
PRINT
PEN RED
PRINT " 9. Exit Game"
PRINT
PEN YELLOW
PRINT " PRESS SELECTION(1-9)"
DO
pop$=INKEY$
IF pop$="1" THEN GOTO viewplayers
IF pop$="9" THEN
COLOR BORDER YELLOW
CLS
PRINT "GAME OVER"
PRINT
PRINT "(C)2025 Chris Grillo"
END
ENDIF
LOOP
GOTO mainmenu
viewplayers:
CLS
COLOR BORDER GREEN
PEN PURPLE
PRINT
CENTRE "Your players"
PRINT
PEN CYAN : PRINT " Pos Name AG SK FI DV GL"
FOR i=0 TO 16
IF i<2 THEN PEN WHITE
IF i>1 THEN PEN YELLOW
IF i>7 THEN PEN GREEN
IF i>13 THEN PEN RED
LOCATE 2,i+4 : PRINT MID$(plyname(i),1)
LOCATE 16,i+4 : PRINT ply_age(i)
LOCATE 19,i+4 : PRINT ply_skl(i)
LOCATE 22,i+4 : PRINT ply_fit(i)
LOCATE 25,i+4 : PRINT ply_dev(i)
LOCATE 28,i+4 : PRINT ply_gls(i)
NEXT
COLOR BORDER YELLOW
PRINT
INK PURPLE
CENTRE "Press any key to return"
WAIT KEY
GOTO mainmenu
Doesn't work on my larger app ... The most I can get to obtain a reliable continuation is 24 teams, though I have to reduce the fixtures.
Here is a mock-up before optimization. Using direct gotos before writing it in modern mode.
48 teams (duplicated just for checking).
Will not even arrive at the fixtures beyond fixt(10) ...
CLS BLACK : PAPER BLACK : COLOR BORDER BLACK : PEN WHITE
'
DIM team(48) AS STRING
DIM fixt(15) AS STRING
DIM plyname(17) AS STRING
DIM day(15) AS INTEGER
DIM result_string(15) AS STRING
DIM xteam(16) AS STRING
DIM vb(16) AS STRING , vc(16) AS STRING
DIM ply_age(17) AS INTEGER , ply_skl(17) AS INTEGER
DIM ply_fit(17) AS INTEGER , ply_dev(17) AS INTEGER
DIM ply_gls(17) AS INTEGER , ply_yel(17) AS INTEGER , ply_red(17) AS INTEGER
DIM won(16) AS INTEGER , drew(16) AS INTEGER , lost(16) AS INTEGER
DIM scored(16) AS INTEGER , conceded(16) AS INTEGER , points(16) AS INTEGER
DIM x_won(16) AS INTEGER , x_drew(16) AS INTEGER
DIM x_lost(16) AS INTEGER , x_scored(16) AS INTEGER
DIM x_conceded(16) AS INTEGER , x_points(16) AS INTEGER
DIM b(16) AS INTEGER , c(16) AS INTEGER
DIM opponent_goalie(16) AS INTEGER
DIM opponent_defence(16) AS INTEGER
DIM opponent_midfield(16) AS INTEGER
DIM opponent_attack(16) AS INTEGER
FOR i=0 TO 16
ply_age(i)=16+INT(RND(14))
ply_skl(i)=6+INT(RND(5))
ply_fit(i)=6+INT(RND(5))
ply_dev(i)=6+INT(RND(5))
ply_gls(i)=6+INT(RND(5))
NEXT
z1=0 : z2=0 : cb=500000 : gu=1 : day=1 : i=0
DO
READ team(i)
PRINT i,team(i)
INC i
IF i=48 THEN EXIT
LOOP
'
DATA "Aldershot ","Barnet ","Barrow "
DATA "Bradford C. ","Bromley ","Carlisle Utd"
DATA "Colchester ","Crewe Alex ","Doncaster "
DATA "Fleetwood ","Gateshead ","Grimsby "
DATA "Halifax ","Hartlepool ","Milton K. "
DATA "Newport ","Oldham Ath. ","Rochdale "
DATA "Southend Utd","Swindon ","Tranmere R. "
DATA "Walsall ","Wimbledon ","York City "
DATA "Aldershot ","Barnet ","Barrow "
DATA "Bradford C. ","Bromley ","Carlisle Utd"
DATA "Colchester ","Crewe Alex ","Doncaster "
DATA "Fleetwood ","Gateshead ","Grimsby "
DATA "Halifax ","Hartlepool ","Milton K. "
DATA "Newport ","Oldham Ath. ","Rochdale "
DATA "Southend Utd","Swindon ","Tranmere R. "
DATA "Walsall ","Wimbledon ","York City "
WAIT 1000 MS : COLOR BORDER GREEN : CLS BLACK
PEN YELLOW : LOCATE 0,0 : i=0
DO
READ fixt(i)
PRINT fixt(i)
INC i
IF i=15 THEN EXIT
LOOP
DATA"01030408051306110715121014021609"
DATA"01140803090610071104121613021505"
DATA"01080215031104090510061214131607"
DATA"01110516070608140903100212041513"
DATA"01090312040706050811131014151602"
DATA"01120206050407030908101511141316"
DATA"01070305040206130812110914101615"
DATA"01050203070809141016121113041506"
DATA"01020313041506100805091211071614"
DATA"01130208051107091004141215031606"
DATA"01150310041606140813090511021207"
DATA"01100209051206041311140715081603"
DATA"01160306041407050810091311151202"
DATA"01060207040310111312140515091608"
DATA"01040314050207130806091011161215"
WAIT 1000 MS
COLOR BORDER YELLOW
CLS BLACK
PEN PURPLE
LOCATE 0,0
i=0
DO
READ plyname(i)
PRINT plyname(i)
INC i
IF i=17 THEN EXIT
LOOP
DATA "(G) Anderson"
DATA "(G) Martin "
DATA "(D) Rogers "
DATA "(D) Kensdale"
DATA "(D) Ralph"
DATA "(D) Ashley"
DATA "(D) Woodman"
DATA "(D) Taylor"
DATA "(M) Bridge"
DATA "(M) Coker"
DATA "(M) Thomas"
DATA "(M) James"
DATA "(M) Blake"
DATA "(M) Crowther"
DATA "(F) Rose"
DATA "(F) Cardwell"
DATA "(F) Powell"
WAIT 1000 MS
CLS BLUE
INK YELLOW:LOCATE 0,8:CENTRE "GRFM2025 Retro 8-bit"
INK GREEN : LOCATE 0,10 : CENTRE "by Chris Grillo"
INK CYAN : LOCATE 0,17 : CENTRE "LOADING."
WAIT 2000 MS
i=0
CLS BLACK
PEN YELLOW
LOCATE 0,0
PRINT "Choose a team to manage"
FOR i=0 TO 15
IF i MOD 2 THEN
PEN WHITE
ELSE
PEN CYAN
ENDIF
PRINT i+1,team(i),i+2,team(i+1)
NEXT
PEN YELLOW
INPUT "Your choice " ; k
IF k<1 OR k>16 THEN k=1
PEN RED
PRINT "You are hired by ";team(k-1)
team(1)=team(k-1)
WAIT 1000 MS
k=0
mainmenu:
CLS BLACK
COLOR BORDER BLUE
LOCATE 0,0
PEN YELLOW
PRINT " Main Desk : " ; team(1)
PEN WHITE
PRINT " 1. Players"
PRINT " 2. League Table"
PRINT " 3. Total Fixtures"
PRINT " 4. Opponent Skill"
PEN CYAN
PRINT " 5. Transfer List"
PEN YELLOW
PRINT " 6. Finances"
PRINT " 7. Stadium"
PEN GREEN
PRINT " 8. Next Match"
PEN RED
PRINT " 9. Exit Game"
PEN YELLOW
PRINT " PRESS SELECTION(1-9)"
DO
pop$=INKEY$
IF pop$="1" THEN GOTO viewplayers
IF pop$="9" THEN
COLOR BORDER YELLOW
CLS
PRINT "GAME OVER"
PRINT "(C)2025 Chris Grillo"
END
ENDIF
LOOP
GOTO mainmenu
viewplayers:
CLS
COLOR BORDER GREEN
PEN PURPLE
CENTRE "Your players"
PEN CYAN : PRINT " Pos Name AG SK FI DV GL"
FOR i=0 TO 16
IF i<2 THEN PEN WHITE
IF i>1 THEN PEN YELLOW
IF i>7 THEN PEN GREEN
IF i>13 THEN PEN RED
LOCATE 2,i+4 : PRINT MID$(plyname(i),1)
LOCATE 16,i+4 : PRINT ply_age(i)
LOCATE 19,i+4 : PRINT ply_skl(i)
LOCATE 22,i+4 : PRINT ply_fit(i)
LOCATE 25,i+4 : PRINT ply_dev(i)
LOCATE 28,i+4 : PRINT ply_gls(i)
NEXT
COLOR BORDER YELLOW
INK PURPLE
CENTRE "Press any key to return"
WAIT KEY
GOTO mainmenu
-
- Site Admin
- Posts: 178
- Joined: Fri Oct 06, 2023 8:25 pm
Re: DATA read problems...
Hi Grillomalta, first of all thanks for the feedback!
As I explained in the group, the string management space is statically allocated, even if it is dynamically managed. The default value is 1024 (bytes) on Commodore 64, to optimize the space occupied by the strings. You can use the DEFINE STRING SPACE command to change this value to a minimum value, if the program does not use strings, or increase it if your program uses many (temporary) strings, as it happens in this case.
In particular, using the command:
you get a program that should work correctly:
Or at least I got to this point, after pressing a series of options. I don't know if it's enough proof because I didn't read the source carefully, but I concentrated on understanding why it stopped, and in order to make it running. Anyway, later you will have to carefully calibrate the value of the parameter of DEFINE STRING SPACE command, to ensure you have the space for the rest of the game.
With this occasion, I would like to advise you about some optimizations.
If value are smaller than 256, it is move convient to use BYTE data type instead of INTEGER. Taking this approach allows you to halve the size of the data and reduce the size of the executable code. In fact, 8-bit processors (like the Commodore 64) do not cope well with data larger than a byte.
If the loops are limited to a range of 0...256, it is convenient to use the BYTE type for these variables as well. In general, the FOR command should be replaced with the more parsimonious DO...INC...LOOP.
The INT function is not necessary to get a random integer: in fact, RND(n) returns a random integer between 0...n-1.
Using MOD to decide whether a number is even or odd is space-consuming because it has to do a division. It is better to use this expression, which takes advantage of the fact that an odd number has the bit in position 0 to 1 (2^0 = 1):
I hope I helped, please let me know.
As I explained in the group, the string management space is statically allocated, even if it is dynamically managed. The default value is 1024 (bytes) on Commodore 64, to optimize the space occupied by the strings. You can use the DEFINE STRING SPACE command to change this value to a minimum value, if the program does not use strings, or increase it if your program uses many (temporary) strings, as it happens in this case.
In particular, using the command:
Code: Select all
DEFINE STRING SPACE 4096
Or at least I got to this point, after pressing a series of options. I don't know if it's enough proof because I didn't read the source carefully, but I concentrated on understanding why it stopped, and in order to make it running. Anyway, later you will have to carefully calibrate the value of the parameter of DEFINE STRING SPACE command, to ensure you have the space for the rest of the game.
With this occasion, I would like to advise you about some optimizations.
Code: Select all
DIM ply_age(17) AS INTEGER , ply_skl(17) AS INTEGER
Code: Select all
FOR i=0 TO 16
Code: Select all
ply_age(i)=16+INT(RND(14))
Code: Select all
IF i MOD 2 THEN
Code: Select all
IF i AND 1 THEN
-
- Posts: 6
- Joined: Mon Dec 30, 2024 1:54 pm
Re: DATA read problems...
Grazie mille per l'aituo imrezzabile. Davvero grande. Anche considerando l'ultimo giorno dell'anno.
Sicuramente prendero' in considerazione tutto il tuo feedback. Sono un po' vecchio nella mia programmazione.
Ho gia' provato INC in Do Loop e ho notato un po di differenza.
Voglio augurarti un buon anno con molto successo con questo meraviglioso pacchetto...
Chris... detto IlGrillo.
-----------------
Thank you for this incredible help. Really great. Then when you consider it is the last day of the year, that is even more appreciated.
I will definitely take your feedback into consideratio. I am a bit of the older generation when it comes to programming.
Have tried the INC in a Do Loop and noticed the difference.
Would like to wish you a Happy New Year with loads of success with this marvelous product... Chris.
Sicuramente prendero' in considerazione tutto il tuo feedback. Sono un po' vecchio nella mia programmazione.
Ho gia' provato INC in Do Loop e ho notato un po di differenza.
Voglio augurarti un buon anno con molto successo con questo meraviglioso pacchetto...
Chris... detto IlGrillo.
-----------------
Thank you for this incredible help. Really great. Then when you consider it is the last day of the year, that is even more appreciated.
I will definitely take your feedback into consideratio. I am a bit of the older generation when it comes to programming.
Have tried the INC in a Do Loop and noticed the difference.
Would like to wish you a Happy New Year with loads of success with this marvelous product... Chris.
-
- Posts: 6
- Joined: Mon Dec 30, 2024 1:54 pm
Re: DATA read problems...
Ciao, funziona tutto. Appena entrato Define String Space, ho funzionato tutto. Messo 2048 invece di 4096.
Ho anche usato gli altri funzioni.
Di nuovo, Grazie Mille. Vado per fare la comprata su itch.
Ho anche usato gli altri funzioni.
Di nuovo, Grazie Mille. Vado per fare la comprata su itch.