Garry's Mod Wiki

debug.setlocal

  string debug.setlocal( thread thread = Current Thread, number level, number index, any value = nil )

Description

This function was removed due to security concerns.

Sets a local variable's value.

Arguments

1 thread thread = Current Thread
The thread
2 number level
The level above the thread. 0 is the function that was called (most always this function)'s arguments

1 is the thread that had called this function.

2 is the thread that had called the function that started the thread that called this function.

3 number index
The variable's index you want to get.

1 = the first local defined in the thread

2 = the second local defined in the thread

4 any value = nil
The value to set the local to

Returns

1 string
The name of the local variable if the local at the index exists, otherwise nil is returned.

Example

Prints the local variables, sets them, then prints the variables again.

local var1 = "Luke, I am not your father." local var2 = "PMFPMF" (function() print("Getting the locals now!") PrintTable({debug.getlocal(2, 1)}) PrintTable({debug.getlocal(2, 2)}) print("\nSetting the locals now!") print(debug.setlocal(2, 1, "I'm actually your mother.")) print(debug.setlocal(2, 2, "Chemo-chi")) print(debug.setlocal(2, 3, "nil should be returned here!")) print("\nHere are the locals after being set!") PrintTable({debug.getlocal(2, 1)}) PrintTable({debug.getlocal(2, 2)}) end)()
Output:
Getting the locals now! 1 = var1 2 = Luke, I am not your father. 1 = var2 2 = PMFPMF Setting the locals now! var1 var2 nil Here are the locals after being set! 1 = var1 2 = I'm actually your mother. 1 = var2 2 = Chemo-chi