|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Fri Oct 15, 2010 12:40 am
luaCOM and variables in sub classes |
If I use the following line and the variable MSDP is listed under the main session, not in any classes I can retrieve the value fine.
Code: |
var = cmuds.getvar(MSDP,"MSDP") |
What would one need to do to access the variable in a class structure like the one below? Nothing i'm trying right now is working I think my brain is just overloaded right now lol.
Code: |
Main_session -- the main session
Class1 -- A class in the main session
Class2 -- A class within Class1 which contains the MSDP variable
|
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Oct 15, 2010 2:40 pm |
You are using the wrong code. You want to use getvar. My Lua in CMUD is a little rusty but I'm not even sure why you're current syntax works at all. The proper syntax is
Code: |
var = zs.getvar("MSDP") |
|
|
_________________ Asati di tempari! |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Fri Oct 15, 2010 4:05 pm |
it works because because i'm am doing this from outside of CMUD? I guess I should have said that in the first post.
Code: |
require("luacom")
require("luacom5")
local data = 1
if data == 1 then
cmud = luacom.CreateObject("cMUD.Application")
cmuds = cmud.CurrentSession
var = cmuds.getvar(MSDP,"MSDP")
val = var.value
end
print(val)
|
I think the zs.whatever stuff only works from within CMUD? I couldn't get it to work from outside. Anyway, the above statement will print the value of the MSDP var to the screen if the MSDP var is directly under the main session. Was just trying to figure out how to access the same variable if it was in a sub class. |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Fri Oct 15, 2010 6:06 pm |
Ok... even if that's the case, I'm not sure I understand why you are passing two arguments to the getvar function. It only takes one parameter, the id of the variable. I wouldn't think the syntax would be
Code: |
var = cmuds.getvar("MSDP") |
The other thing to note is "zs" represents a CMUD Window Object, and it looks like you are loading the session object. So you may also have to explicitly get a window object by doing something like
Code: |
testwin = cmuds.windows["myWindowName"]
var = testwin.getvar("MDSP") |
I've never tried scripting CMUD from external Lua, so it's all really an educated guess, at best. |
|
_________________ Asati di tempari! |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Fri Oct 15, 2010 8:45 pm |
From the cMUD type library:
Code: |
GetVar
IDispatch* GetVar(BSTR Name, BSTR ClassName)
LuaCOM examples:
retval = com_obj:GetVar(Name, ClassName) |
That's where I came up with the two parameter syntax used with GetVar(). However the object notes for GetVar() state:
Code: |
Function GetVar(Name As String, ClassName As String) As cMUDVar |
I've added quotes around the name passed to the function now, so I have
Code: |
require("luacom")
require("luacom5")
local data = 0
if data == 0 then
cmud = luacom.CreateObject("cMUD.Application")
cmuds = cmud.CurrentSession
var = cmuds.GetVar("MSDP","MSDP")
val = var.value
end
print(val)
|
This is a trial and error learning process for me. So I don't understand everything that is happening. Like why GetVar("MSDP","MSDP") is taking the second "MSDP" as a class since there is no such class in the session.
I can't find anything related to zs.function objects in the type library so i'm trying to stay away from them right now since this is all being done outside of CMUD. It seems to me Either the object notes for the GetVar() function is are wrong or there is something strange happening there perhaps? I'm using 3.30 so I guess I should probably make a new post in the beta forum about this. I didn't think it was gonna turn into a possible bug situation though. If someone wants to move this over before I get a chance to that would be cool. |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
|
|