There is a webpage “Forcing a variable to exist”:
https://www.bbcbasic.net/wiki/doku.php? ... to_20exist
Out of curiosity:
How would I best do the same for an array?
array() = array()
array() += 0
won’t work because of the necessary DIM statement when creating an array.
I found a solution suitable for my needs:
Try one of the above solutions in a PROC, and create the array in some local ERROR code if it fails.
But what if I want to force several arrays to exist? The ERROR code won’t know which arrays need to be created.
Is there a best-practice for this?
Can it be achieved outside of a PROC/FN?
Forcing an array to exist.
-
- Posts: 19
- Joined: Fri 08 Jul 2022, 02:47
- Location: England
Forcing an array to exist.
Finishing that game Any Decade Now™
-
- Posts: 366
- Joined: Tue 18 Jun 2024, 09:32
Re: Forcing an array to exist.
A couple of ways to 'force' an array to exist are to return its address:
Code: Select all
address%% = ^array()
Code: Select all
LOCAL array()
Code: Select all
pointer%% = PTR(array())
An additional (but probably less useful) way to create an array is to specify it as a RETURNed parameter:
Code: Select all
PROCtest(array())
END
DEF PROCtest(RETURN a())
ENDPROC