19. Reference Variables

[<<<] [>>>]

Even if you did not realize, you have already met reference variables in ScriptBasic. These are variables, which have no values for themselves but rather reference another variable and whenever they are accessed the other variable is accessed actually (With some few exceptions, which are cases that help handling reference variables.)

The arguments of functions and subroutines are examples. These variables refer to the variable that stands in the calling expression. For example:

sub myfunction(a)
  a = a + 1
end sub
b = 3
myfunction b

will increase the value of the global variable b, because a references this variable.

This is pretty automatic and there would be no need to devote a special chapter to such a phenomenon, but there is more. Not only argument variables of functions and subroutines can be reference variables but any variable using the reference assignment. This is almost like a normal assignment. The difference in the syntax is that the command starts with the keyword REF and the right side of the assignment can not be just any expression, but a variable that the left side is going to reference. For example:

a = 13
REF b = a
b += 1
print a

will print 14 because b is the "same" as a after the REF assignment.

TO BE CONTINUED... ***TODO***


[<<<] [>>>]