SetRef

Function

Syntax

Writes a value into the variable, field, array cell, list element or map entry that a handle points at.

SetRef(<handle>, <value>)

Parts

<handle>A handle made with @target.
<value>The value to write. It is converted to the target's type, as any write to that target would be.

Returns

The value actually stored, after conversion: SetRef(h, 300) on an AS uint8 target returns 44.

Good to know

  • The target's type wins: a handle to an AS integer variable drops decimals, one to an AS uint8 variable wraps at 256.
  • On a released handle, the program stops with "BASIC reference handle has been released". On a HANDLE variable never assigned, it stops with "BASIC value is not a reference handle".
  • Unlike a REF parameter, a handle can be kept in a variable, a record or a list and used later.

Example

FUNCTION AddGold(target AS HANDLE, amount AS integer)  SetRef(target, GetRef(target) + amount)ENDFUNCTIONgold AS integer = 5AddGold(@gold, 10)Console(Str(gold))   ' 15small AS uint8 = 0Console(Str(SetRef(@small, 300)))   ' 44
In the manual : Functions