Is it possible to set a variable without having coded for that specific variable to be changed?
eg
If I look at an object/entity
Speak the words
Set VARNAME = VARVALUE (Where VARNAME is the name of the variable, and VARVALUE = the variable value I wish to change it to)
And then VARVALUE replaces the value of VARNAME.
Can this be done?
Are variables on entities exposed as NetworkedStrings/Int's etc
Can the SetNetworkedString & SetNetworkedInt functions change variables?
I'd like to be able to programatically change a variable value from ingame.
[editline]2nd May 2011[/editline]
Or even another example
[LUA]
local ent = SomeEntity
local varTable = { "first","second","third"}
for k, v in pairs(varTable) do
ent.v = someValue
end
[/LUA]
Is the above do-able?
eg - Taking a string, and using it as a reference to a variable?
[QUOTE=Baaleos;29569609]Is it possible to set a variable without having coded for that specific variable to be changed?[/QUOTE]
Yes.
[lua]local ent = SomeEntity
local key = "name"
ent[key] = someValue[/lua]
Your second example has a small mistake though. Using ent.v would try to access the key "v", what you want in ent[v], which would access the correct one.
Thanks raBBish,
Thats great.
I run a server with the Networked Personal Fairies, and I plan on introducing a chat command that allows fairies to modify variables on other entities.
Sort of like turning them into a Debug Tool, or a cheat tool. hehe.
I have plans on making them capable of modifying the Carters Pack Dakara Superweapon, to target custom entity classes.
[LUA]
ent = TheDakaraSuperWeapon
command = "insert" -- Used to insert into a table, also identifies that the variable we are modifying is a table
varName = "Targets"
argVal = "ZPM"
(chat command would be: *FairyName* insert ZPM into Targets ) * While looking at the entity
table.insert(ent[varName],argVal) -- Inserts ZPM into the targets list
[/LUA]
Sorry, you need to Log In to post a reply to this thread.