LoginLogin

Multi-slot question

Root / Programming Questions / [.]

MinxrodCreated:
Variables are bound to the slot they are in. Doing EXEC or USE will reset the state of variables declared in that slot. You can access variables from other slots by using VAR() e.q:
VAR("2:mySlot2Var") = 42

I CAN? :O Does that work with arrays? also sorry deleted post :/

Yes, it does work with arrays.
VAR("2:mySlot2Arr")[0]=42

Oh, I was trying to do it wrong XD I tried VAR("1:mySlotArr[0]") Thank you so much :D TIDE: Also inline code woohoo :P

Is this a secret command?

Is this a secret command?
Ssh! Don't tell anybody!

Is this a secret command?
Ssh! Don't tell anybody!
It's a secret...

Wow, this is awesome!!! VAR is the best command ever! (the only way to access the hidden "variable name" type) SB actually has 5 variable types: integer% double# string$ array[] VAR("variable")

Wow, this is awesome!!! VAR is the best command ever! (the only way to access the hidden "variable name" type) SB actually has 5 variable types: integer% double# string$ array[] VAR("variable")
I disagree - VAR is not a variable type, instead, it's a method that returns a variable - and the variable is always one of the other types. And for the record, the types are: integer% double# (are you sure it's double and not single-precision float?) string$ intarray%[] dblarray#[] strarray$[] :D

Try doing INC without using the special type!
INC SCORE,100
       ^what is this???
Actually, there are fewer types: -number (integer/double) -array (string/character/integer/double)* -variable name *strings are just arrays of characters

Arrays technically aren't types, you could consider them pointers or data structures. A string is technically a type since you can have an array of them. VAR ain't. And yeah, they are doubles according to the specs.
Data Type (#) Double-precision Real Data Type (variables ending with #)

Pointers and data structures are types.

I like to think that there's: CHARACTER_ARRAY$ (or STRING$) CHARACTER_ARRAY_ARRAY$[] (or STRING_ARRAY$[]) INTEGER% INTEGER_ARRAY%[] REAL# REAL_ARRAY#[] Note that if a type isn't specified, it is assumed real unless you have OPTION DEFINT running, in which case it is assumed integer. Also, you can apparently do:
DIM S$[1]
S$[0]=" "
?S$[0][0]

I like to think that there's: CHARACTER_ARRAY$ (or STRING$) CHARACTER_ARRAY_ARRAY$[] (or STRING_ARRAY$[]) INTEGER% INTEGER_ARRAY%[] REAL# REAL_ARRAY#[] Note that if a type isn't specified, it is assumed real unless you have OPTION DEFINT running, in which case it is assumed integer. Also, you can apparently do:
DIM S$[1]
S$[0]=" "
?S$[0][0]
Exactly! ^_^ (this is exactly what I said, you just worded it better)

What variable type is returned by VAR() then?

What variable type is returned by VAR() then?
It doesn't return a variable, it returns a reference to one. VAR("A%")=2 is the same as writing A%=2.

Is it possible to access DATA declared in different slots, or would it need to be READ to an array in said slot?

Is it possible to access DATA declared in different slots, or would it need to be READ to an array in said slot?
When you specify DATA SB keeps it in a central location until the next READ instruction, so yes it's accessible. EDIT: This post was about a different programming language. Changed it to be SmileBasic.

Can't you RESTORE data in other slots, by doing RESTORE "1:@..." or can you not do that with RESTORE and DATA?

Can't you RESTORE data in other slots, by doing RESTORE "1:@..." or can you not do that with RESTORE and DATA?
I originally answered the same way, but tested it and couldn't get it to work. If you're not an idiot, this works great! I had:
PRG0
----
USE 1
VAR A,B,C
RESTORE "1:@TEST"
READ A,B,C

?A
?B
?C
and
PRG1
----
@TEST
DATA 1,2,3,4,42
EDIT: I herp derped pretty baldly. I think I unherped. I apologize for any derps.