• Do not use Works in Progress as a way of avoiding the releases system! Works in Progress can be used for sharing early betas and for getting suggestions for improvement. Releases of finished content are not allowed in this forum! If you would like to submit a finished addon, click here for instructions on how to do so.

Accesing and editing a CVAR in Lua

Status
Not open for further replies.

amperbee

thunderdome denizen
Another problem.
I'm understanding Lua so I'm having way lesser problems than I had before.

How do I make a CVAR and how do I access it?
I made a CVAR but everytime I access it to set a variable with the value of this CVAR, it says it has a problem because Lua expected a number and not userdata.
Then how do I use the CVAR I just made, making sure only the server/admin can edit it and accesible for Lua?
 
You make a cvar using the CV_RegisterVar function, which returns the consvar_t data for the new cvar created:
https://wiki.srb2.org/wiki/Lua/Functions#CV_RegisterVar

Code:
local mycvar = CV_RegisterVar(table of data, see wiki)

Refer to this for dealing with the variable itself (note you cannot directly modify it in this manner):
https://wiki.srb2.org/wiki/Lua/Userdata_structures#consvar_t

If you DO intend to manually edit it's value, you may be better off using CONS_BufInsertText and using "mycvarname value" to run it in the console:
https://wiki.srb2.org/wiki/Lua/Functions#COM_BufInsertText
 
Thank you Monster Iestyn, I don't know how did I miss that part.
I just needed to access the CVAR.
 
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top