Tutorial: How to get a reference to a Variable
Posted: Mon May 12, 2025 2:32 pm
Came to my mind this could be useful to others too.
As Hollywood doesnt normally support References to variables, here is how to get something equivalent to a reference to a variable In Hollywood.
Result:
3
4
Do notice it is recommended to use small letters in variable names, as example, using:
would not work correctly since it would be trying to access TestTable["B"] instead of TestTable["b"]
Point for using noncapitalized is that there is no way to access Capital Letter named variables through regular table.var suffix.
You can assign, and then access it using
But if you would try to access it using either:
they would both be trying to access TestTable.["b"]
While ["abc"], ["Abc"], and ["ABC"] all create their own unique variable, only way to access Abc or ABC, is by using table["Abc"], table["ABC"], everything else would try to access Table["abc"]
as example:
are all referring to Table.abc / Table["abc"]
As Hollywood doesnt normally support References to variables, here is how to get something equivalent to a reference to a variable In Hollywood.
Code: Select all
Function NewValueToVarReference(Table, Var, NewValue)
Table[Var] = NewValue
EndFunction
TestTable = {a = 1, b = 2}
NewValueToVarReference(TestTable, "a", 3)
VarToUse = "b"
NewValueToVarReference(TestTable, VarToUse, 4)
DebugPrint(TestTable.a)
DebugPrint(TestTable.b)
3
4
Do notice it is recommended to use small letters in variable names, as example, using:
Code: Select all
VarToUse = "B"Point for using noncapitalized is that there is no way to access Capital Letter named variables through regular table.var suffix.
You can assign
Code: Select all
TestTable["B"] = 2Code: Select all
Debugprint(TestTable["B"])Code: Select all
TestTable.b
TestTable.BWhile ["abc"], ["Abc"], and ["ABC"] all create their own unique variable, only way to access Abc or ABC, is by using table["Abc"], table["ABC"], everything else would try to access Table["abc"]
as example:
Code: Select all
Table.abc
Table.Abc
Table.ABC