saverestore.ReadVar

From GMod Wiki

Revision as of 14:58, 13 September 2009 by UnrealomegaBot (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Function
Syntax saverestore.ReadVar( Table restore )
Where is this used?
Description:
Reads a single variable of any type.
Returns: Var
Part of Library: saverestore
Realm: NewerShared.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Saverestore.ReadVar]Saverestore.ReadVar [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]


Examples

DescriptionHooks a save and restore function to save my_table and my_var.
Used onNewerShared.png
Code
local function MySaveFunction(save)
   saverestore.WriteVar(my_var, save)
   saverestore.WriteTable(my_table, save)
   //this function call is equivalent to the one above.
   //saverestore.WriteVar(my_table, save)
end
 
local function MyRestoreFunction(restore)
   my_var = saverestore.ReadVar(restore)
   my_table = saverestore.ReadTable(restore)
   //this function call is equivalent to the one above.
   //my_table = saverestore.ReadVar(restore)
end
 
saverestore.AddSaveHook( "HookNameHere", MySaveFunction )
saverestore.AddRestoreHook( "HookNameHere", MyRestoreFunction )
 
OutputN/A
DescriptionDemonstrates determining the type of a variable read.
Used onNewerShared.png
Code
local function MyRestoreFunction(restore)
   my_var = saverestore.ReadVar(restore)
   var_type = type(my_var)
end
 
Outputvar_type will equal "string" if ReadVar returned a string, "number" for a float/integer etc.


Additional Notes

See Also

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox