LoginLogin

Store label in array?

Root / Programming Questions / [.]

VakoreCreated:
I'm trying to store labels in an array. You can store them as variables, but I was wondering how you could store them in an array. Whenever I try to I get an error. Thanks!

Out of curiosity, what kind of error are you getting? My 3DS isn't on hand but I plan to experiment when I get the chance.

Something about wrong reference type(like if you were to try and put a string in an integer variable).

I forgot if it's possible, but are you by chance doing a string array? In theory, just doing below would work just fine.
var array$[4]
array$[0]="@test1"
array$[1]="@test2"
gosub array$[0]
print "EOF"

@test2
print "world"
return

@test1
print "Hello!";
gosub array$[1]
return
Alternatively, you could make it one step more complicated by defining a string variable that takes on the array variable's contents dependent on another variable. Like so.
var array$[4]
var CO
var RE$
array$[0]="@test1"
array$[1]="@test2"
while true
RE$=array$[CO]
gosub RE$
wend

@test2
print "world"
CO = 0
return

@test1
print "Hello!";
CO = 1
return

DIM ARR$[2]
ARR$[0]="@IFYOUYEETYOURTACOSYOUWILLHAVE0PI"
ARR$[1]="@37IS37
RESTORE ARR$[0]
RESTORE ARR$[1]

@IFYOUYEETYOURTACOSYOUWILLHAVE0PI
DATA 17
@37IS37
DATA 37

Whaddayaknow, referencing a string can count as a label. Thanks guys!

Glad we could help!