问题描述
可以从侦听器内创建一个对象(某些类)吗?
我试过,但是我收到一个错误:``class not found''。
我想做一些类似的事情:
class ONE {
class_ONE_code
}
class TWO {
object o = ONE)
}
我需要这个来创建一个新的监听器,当我执行另一个监听器。
你希望做什么当然是可能的。您的代码中可能会出现语法错误。例如,您的类TWO的实现是无效的,因为类代码的成员声明部分中不能初始化类似o的成员变量。这只能在类方法中完成,如下面的示例代码所示。
class One
{
void DoClassOneAction(Object self)
{
OKDialog(执行一级操作);
}
}
class Two
{
Object oneInstance;
void DoClassTwoAction(Object self)
{
if(!oneInstance.ScriptObjectIsValid())
oneInstance = Alloc(One);
oneInstance.DoClassOneAction();
}
}
void main()
{
对象twoInstance = Alloc(Two);
twoInstance.DoClassTwoAction();
}
main();
请注意,DM脚本类的编码要求与支持对象的其他语言的编码要求有所不同。您可能需要查看DM在线帮助的脚本>对象部分中的详细信息(通过帮助>搜索...菜单项访问)。
I'm creating a script and have troubles.
Is it possible to create an object (of some class) from within a listener?I tried it but I get an error: ``class not found''.
I want to do something like:
class ONE {
class_ONE_code
}
class TWO {
object o = alloc(ONE)
}
I need this to create a new listener when I execute another listener.
What you wish to do is certainly possible. Most likely you have a syntax error in your code. For example, your implementation of class TWO is invalid since a member variable like "o" cannot be initialized in the member declaration section of the class code. This can only be done within a class method, as illustrated in the example code below.
class One
{
void DoClassOneAction(Object self)
{
OKDialog("Class One action executed.");
}
}
class Two
{
Object oneInstance;
void DoClassTwoAction(Object self)
{
if (!oneInstance.ScriptObjectIsValid())
oneInstance = Alloc(One);
oneInstance.DoClassOneAction();
}
}
void main()
{
Object twoInstance = Alloc(Two);
twoInstance.DoClassTwoAction();
}
main();
Note that the coding requirements for DM script classes differ somewhat from those of other languages that support objects. You may want to review details in the Scripting > Objects section of the DM on-line help (accessed via Help > Search… menu item).
这篇关于在侦听器中创建一个对象(某些类)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!