这篇条目有关 Source引擎。如需详情,点击这里。
这篇条目有关 Source 2引擎。如需详情,点击这里。

Zh/Logic script: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
(Created page with "{{LanguageBar}} {{Source topicon}} {{Source 2 topicon}} {{tabsBar|main=s2|base=logic_script}} {{CD|CLogicScript|CPointEntity|file1=1}} __NOTOC__ left|Source 1编辑器图标 left|Source 2编辑器图标 {{this is a|逻辑实体|name=logic_script|since=Left 4 Dead 2}} 该实体在{{tf2branch|4}}和{{mapbase|4}}中也可用。 此实体作为{{L|VScript}}的容器。例如在Left 4 Dead 2中,它被广泛用于...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:
{{KV Targetname}}
{{KV Targetname}}
{{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination
{{KV|EntityGroup[0]|intn=Group00|to=EntityGroup[15]|intn2=Group15|target_destination
|3=指定实体名称使其可在Squirrel代码中访问。所有指定实体名称会在该实体生成时被搜索,其[[VScript Fundamentals#Script Handles|脚本句柄]]将被添加到此<code>logic_script</code>的脚本作用域:
|3=指定实体的目标名称(Targetnames),使其在Squirrel代码中可访问。该实体生成时,将搜索所有指定的实体名称,并将它们的{{L|VScript Fundamentals#脚本句柄|脚本句柄}}添加到此<code>logic_script</code>的脚本作用域中:
:*<code>EntityGroup</code>: 数组,其中<code>EntityGroup[0]</code>对应'''EntityGroup[0]'''键值指定名称的实体句柄。若存在多个同名实体,则使用第一个找到的句柄。数组长度为最高非空EntityGroup索引加一,因此在Squirrel代码中不要硬编码不确定长度的索引。
:<code>EntityGroup</code>:一个数组,其中<code>EntityGroup[0]</code>是名为'''EntityGroup[0]'''键值所指定实体的句柄,以此类推。如果存在多个同名实体,则使用找到的第一个句柄。数组长度为最高非空EntityGroup索引加一,因此在Squirrel代码中,若长度不确定,请勿硬编码索引。若键值'''EntityGroup[i]'''为空字符串(<code>i < EntityGroup.len()</code>),则<code>EntityGroup[i]</code>为<code>null</code>。
:*<code>MyEntityGroup</code> {{csgo|不包含}}: 表结构,键为名称,例如若'''EntityGroup[2]'''设为<code>sound.start</code>,则<code>MyEntityGroup["sound.start"] == EntityGroup[2]</code>。
:<code>MyEntityGroup</code> {{csgo|not}}:一个表(table),其中键为名称,值为句柄。例如,若'''EntityGroup[2]'''键值设为<code>sound.start</code>,则<code>MyEntityGroup["sound.start"] == EntityGroup[2]</code>。
:*<code>MyEntityGroupArray</code> {{csgo|不包含}}: 与<code>EntityGroup</code>相同的数组。
:*<code>MyEntityGroupArray</code> {{csgo|not}}:一个与<code>EntityGroup</code>相同的数组。
:{{expand|title=实现此功能的内部VScript|
:{{expand|title=内部运行的VScript实现此功能|
当logic_script生成时会自动执行以下VScript。<code>__AppendToScriptGroup</code>会对每个<code>Group00</code>-<code>Group15</code>键值指定的名称调用。
以下VScript在<code>logic_script</code>生成时在其作用域中运行,随后以<code>Group00</code>-<code>Group15</code>键值指定的每个名称调用<code>__AppendToScriptGroup</code>。
<syntaxhighlight lang=js>EntityGroup <- [];
<syntaxhighlight lang=js>EntityGroup <- [];
MyEntityGroup <- {};
MyEntityGroup <- {};
Line 44: Line 44:
}
}
}</syntaxhighlight>
}</syntaxhighlight>
}}}
}}}}


{{note|关于其他重要VScript键值如'''vscripts'''、'''thinkfunction'''及输入如'''RunScriptCode'''、'''CallScriptFunction''',请参阅[[Generic Keyvalues, Inputs and Outputs]]}}
{{note|关于其他重要VScript键值如'''vscripts'''、'''thinkfunction'''及输入如'''RunScriptCode'''、'''CallScriptFunction''',请参阅[[Generic Keyvalues, Inputs and Outputs]]}}

Latest revision as of 01:46, 5 July 2025

English (en)中文 (zh)Translate (Translate)

C++ 类层级
CLogicScript
CPointEntity
CBaseEntity
C++ logicentities.cpp
Source 1编辑器图标
Source 2编辑器图标

logic_script是一个逻辑实体,可在所有的 起源 起源 游戏,自从 求生之路2 求生之路2 以来中使用。 该实体在军团要塞2分支 军团要塞2分支Mapbase Mapbase中也可用。

此实体作为VScript(en)的容器。例如在Left 4 Dead 2中,它被广泛用于"黑色狂欢节"的逻辑控制,如《黑色狂欢节》战役中的Peanut Gallery(花生画廊)、Strongman Contest(大力士比赛)、Whack-a-Stach(打鼹鼠)等

Note.png注意:此实体被计为edict(en),而非预期的逻辑实体。

键值

Name (目标名称) <target_source>[ Edit ]
这个名称是其他实体通过 输入/输出(en) 或其他 关键值(en)(如 parentnametarget) 来引用该实体时使用的标识符。
该名称也会显示在 Hammer 编辑器的 2D 视图和 实体报告(en) 中。
参见:  所有实体均可使用的 通用键值、输入与输出(en)

EntityGroup[0] (Group00) to EntityGroup[15] (Group15) <target_destination>
指定实体的目标名称(Targetnames),使其在Squirrel代码中可访问。该实体生成时,将搜索所有指定的实体名称,并将它们的脚本句柄(en)添加到此logic_script的脚本作用域中:
EntityGroup:一个数组,其中EntityGroup[0]是名为EntityGroup[0]键值所指定实体的句柄,以此类推。如果存在多个同名实体,则使用找到的第一个句柄。数组长度为最高非空EntityGroup索引加一,因此在Squirrel代码中,若长度不确定,请勿硬编码索引。若键值EntityGroup[i]为空字符串(i < EntityGroup.len()),则EntityGroup[i]null
MyEntityGroup (存在于 反恐精英:全球攻势):一个表(table),其中键为名称,值为句柄。例如,若EntityGroup[2]键值设为sound.start,则MyEntityGroup["sound.start"] == EntityGroup[2]
  • MyEntityGroupArray (存在于 反恐精英:全球攻势):一个与EntityGroup相同的数组。
内部运行的VScript实现此功能

以下VScript在logic_script生成时在其作用域中运行,随后以Group00-Group15键值指定的每个名称调用__AppendToScriptGroup

EntityGroup <- [];
MyEntityGroup <- {};
MyEntityGroupArray <- EntityGroup;
function __AppendToScriptGroup( name ) 
{
	if ( name.len() == 0 ) 
	{ 
		EntityGroup.append( null ); 
	} 
	else
	{ 
		local ent = Entities.FindByName( null, name );
		EntityGroup.append( ent );
		if ( ent != null )
		{
			ent.ValidateScriptScope();
			MyEntityGroup[name] <- ent;
			ent.GetScriptScope().EntityGroup <- EntityGroup;
		}
	}
}
Note.png注意:关于其他重要VScript键值如vscriptsthinkfunction及输入如RunScriptCodeCallScriptFunction,请参阅Generic Keyvalues, Inputs and Outputs

另见

外部链接