debug.setlocal

From Garry's Mod
Jump to: navigation, search
 debug.setlocal( )

Contents

Description

This page has been nominated for deletion.
Reason for deletion: This function was removed due to security concerns.

Sets a local variable's value.

Arguments

thread thread=Current Thread

The thread

Arguments

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.

Arguments

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

Arguments

any value=nil

The value to set the local to

Returns

string

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

Examples

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
Personal tools
Navigation