Writing into an array

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
nvingo
Posts: 41
Joined: Sat 28 May 2022, 22:40

Re: Writing into an array

Post by nvingo »

Hated Moron wrote: Mon 30 May 2022, 09:39
nvingo wrote: Mon 30 May 2022, 09:12 It seems from the OP that the 22 values (i=0 TO 21) are being calculated with the user-defined function FN_Cavendish
Yes, but the actual question he asked was "I got a "LINE TOO LONG" error and the file closed. Is there a function like APPEND that adds data to an array?" so that's what my reply addressed - if not for the benefit of the OP in his specific circumstances but for more general interest.

It could also be that FN_Cavendish is a very slow and/or large function that one does not want to run every time the program is executed, if all it does is create a set of 'constants'.
I tried to see beyond the error to what the OP wished to achieve; now that he knows how to assign a value to each element he can either do so on each program run directly, or create a file of values on first run which can be read into the array on subsequent runs.
In this instance there are only 22 items to create from the function; given the speed with which BBC BASIC SDL2 generates a Mandelbrot plot (each pixel generated from an iterative loop of imaginary number equations) I doubt FN_Cavendish will give it too much trouble.
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.
Hated Moron

Re: Writing into an array

Post by Hated Moron »

nvingo wrote: Mon 30 May 2022, 15:35 I tried to see beyond the error to what the OP wished to achieve
OK, but I try also to consider other members, who may perhaps find the thread in a search (even years hence), and who might be interested in the issues raised more generally in the OP's question rather than the narrow specifics of his application.

If you still think my replies are unhelpful feel free to report them to the admin (see my signature). My presence here is barely tolerated and very much 'probationary'.
nvingo
Posts: 41
Joined: Sat 28 May 2022, 22:40

Re: Writing into an array

Post by nvingo »

Hated Moron wrote: Mon 30 May 2022, 16:30If you still think my replies are unhelpful feel free to report them to the admin (see my signature). My presence here is barely tolerated and very much 'probationary'.
I'm new here too, joined almost 8 weeks later than your good self; hence why I'm also trying to clear up a few unresolved threads only now.
Started using BASIC circa 1981 with CP/M, Video Genie, Sinclair ZX81, Acorn Atom, and progressed with ZX Spectrum, BBC Micro and Sinclair QL, Cambridge Z88, DOS, Windows. Wrote A-level project using school's BBC Micro with dual 800K floppy drive.
zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Writing into an array

Post by zeynel1 »

Hated Moron wrote: Mon 30 May 2022, 15:00
Is it specifically the font that's not being saved/restored...
As far as I can tell only the font size.
Hated Moron

Re: Writing into an array

Post by Hated Moron »

zeynel1 wrote: Tue 31 May 2022, 06:48 As far as I can tell only the font size.
On what platform is this (Windows, MacOS etc.)?

Did you try my suggestion of deleting the sdlide.ini file?
zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Writing into an array

Post by zeynel1 »

Hated Moron wrote: Tue 31 May 2022, 08:31 On what platform is this (Windows, MacOS etc.)?
It's Mac.
Hated Moron wrote: Tue 31 May 2022, 08:31
Did you try my suggestion of deleting the sdlide.ini file?
No. I'm confused about @usr$ notation. Is this the home directory where BBCBasic resides: /Users/a/Library/Application Support/BBCBasic/
Hated Moron

Re: Writing into an array

Post by Hated Moron »

zeynel1 wrote: Tue 31 May 2022, 12:22 No. I'm confused about @usr$ notation. Is this the home directory where BBCBasic resides
I don't know exactly where it will be on your Mac (that's why it's a variable!) but of course it's trivial to discover that either by writing a one-line program or in immediate mode:

Code: Select all

      PRINT @usr$
It's the same for any of the other system variables, if you need to know their values just PRINT them:

Code: Select all

      PRINT @dir$
      PRINT @lib$
      PRINT @cmd$
      PRINT @tmp$
:D
zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Writing into an array

Post by zeynel1 »

Hated Moron wrote: Tue 31 May 2022, 13:01 @usr$
Great, thanks.

Code: Select all

      >PRINT @usr$
/Users/a/Library/Application Support/BBCBasic/
But I don't see the .ini file there.

How do I use @usr$ ?

In my root directory, I created a folder BBCBasic and I want to put all my files there. When I use spool how do I let Basic know that output.txt is in /Users/a/BBCBasic/output.txt?

By the way, I could not save the file as output.txt, but it saves it as output.bas. Is ".txt" ".bas" in Basic?

Code: Select all

      *spoolon output.bas
Hated Moron

Re: Writing into an array

Post by Hated Moron »

zeynel1 wrote: Tue 31 May 2022, 17:09 But I don't see the .ini file there.
I don't understand how SDLIDE can be remembering any of your settings (which you said it is, apart from the fonts) unless the file is there. Here's the code in SDLIDE.bbc which sets the file path:

Code: Select all

      IniFile$ = @usr$ + "sdlide.ini"
When I use spool how do I let Basic know that output.txt is in /Users/a/BBCBasic/output.txt?
I don't recommend using an 'absolute' path like that, because it makes your code non-portable. But if you really want to spool to that specific file it's simply a case of doing:

Code: Select all

*spool "/Users/a/BBCBasic/output.txt"
Or, using OSCLI:

Code: Select all

OSCLI "spool ""/Users/a/BBCBasic/output.txt"""
(quotes must be doubled in a literal string).
I could not save the file as output.txt, but it saves it as output.bas. Is ".txt" ".bas" in Basic?
BBC BASIC program files are usually saved in 'tokenised' format with the extension .bbc (that's the format required for the INSTALL and CALL statements, for example). But you can alternatively save a program in 'plain text' format and, yes, that is generally given a .bas extension. The extension is supposed to indicate what the file is for, so giving a BBC BASIC program a generic .txt extension doesn't really do that.

But ultimately it's up to you whether to follow conventions or not.
Hated Moron

Re: Writing into an array

Post by Hated Moron »

Hated Moron wrote: Tue 31 May 2022, 17:58 I don't understand how SDLIDE can be remembering any of your settings (which you said it is, apart from the fonts) unless the file is there.
In case it's relevant, I'd just like to add that SDLIDE saves your settings (and fonts, etc.) to the sdlide.ini file on exit (e.g. clicking on the close button in the title bar). If you were to shut down your Mac with SDLIDE still running, or to exit the program in some other way without closing it properly (I'm not sure what that might be on a Mac), it could bypass saving the settings to sdlide.ini.