This article's documentation is for anything that uses the Source engine. Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Logic script: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
No edit summary
Tag: Reverted
Line 13: Line 13:
{{clr}}
{{clr}}


== KeyValues ==
== 键值 ==
{{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=Targetnames of entities to make them accessible in Squirrel code. All specified entity names will be searched for upon this entity spawning and their [[VScript Fundamentals#Script Handles|script handles]] are added to this <code>logic_script</code>'s script scope:
|3=指定实体的目标名称(Targetnames),使其在Squirrel代码中可访问。该实体生成时,将搜索所有指定的实体名称,并将它们的{{L|VScript Fundamentals#脚本句柄|脚本句柄}}添加到此<code>logic_script</code>的脚本作用域中:
:*<code>EntityGroup</code>: an array where <code>EntityGroup[0]</code> is the handle of an entity with the name specified in the '''EntityGroup[0]''' keyvalue etc. If multiple entities exist with that name, the first handle found is used. The array length is the highest non-empty EntityGroup index that is not empty plus one, so in Squirrel code, be sure to not hardcode indices if the length is uncertain. If the keyvalue '''EntityGroup[i]''' is the empty string (for <code>i &lt; EntityGroup.len()</code>), then <code>EntityGroup[i]</code> is <code>null</code>.
:<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|not}}: a table which contains the handles with keys being the names, for example if the '''EntityGroup[2]''' keyvalue is set to <code>sound.start</code>, then <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|not}}: an array which is the same as <code>EntityGroup</code>.
:*<code>MyEntityGroupArray</code> {{csgo|not}}:一个与<code>EntityGroup</code>相同的数组。
:{{expand|title=VScript run internally to achieve this|
:{{expand|title=内部运行的VScript实现此功能|
The following VScript is run in logic_script scope when it spawns. <code>__AppendToScriptGroup</code> is then called with each name specified by <code>Group00</code>-<code>Group15</code> keyvalues.
以下VScript在<code>logic_script</code>生成时在其作用域中运行,随后以<code>Group00</code>-<code>Group15</code>键值指定的每个名称调用<code>__AppendToScriptGroup</code>。
<syntaxhighlight lang=js>EntityGroup <- [];
<syntaxhighlight lang=js>EntityGroup <- [];
MyEntityGroup <- {};
MyEntityGroup <- {};

Revision as of 01:37, 5 July 2025

English (en)中文 (zh)Translate (Translate)
C++ Class hierarchy
CLogicScript
CPointEntity
CBaseEntity
C++ logicentities.cpp
Source 1 editor sprite
Source 2 editor sprite

logic_script is a logical entity available in all Source Source games since Left 4 Dead 2 Left 4 Dead 2. It is also available in the Team Fortress 2 branch Team Fortress 2 branch and Mapbase Mapbase.

This entity functions as a container for VScripts. In Left 4 Dead 2, for example, it is used extensively for the logic in "carnival games" found in the Dark Carnival campaign, such as Peanut Gallery, Strongman Contest, Whack-a-Stach, etc.

Note.pngNote:This entity counts as an edict, not a logical entity as one would expect.

键值

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

EntityGroup[0] (Group00) to EntityGroup[15] (Group15) <targetname>
指定实体的目标名称(Targetnames),使其在Squirrel代码中可访问。该实体生成时,将搜索所有指定的实体名称,并将它们的脚本句柄(en)添加到此logic_script的脚本作用域中:
EntityGroup:一个数组,其中EntityGroup[0]是名为EntityGroup[0]键值所指定实体的句柄,以此类推。如果存在多个同名实体,则使用找到的第一个句柄。数组长度为最高非空EntityGroup索引加一,因此在Squirrel代码中,若长度不确定,请勿硬编码索引。若键值EntityGroup[i]为空字符串(i < EntityGroup.len()),则EntityGroup[i]null
MyEntityGroup (not in Counter-Strike: Global Offensive):一个表(table),其中键为名称,值为句柄。例如,若EntityGroup[2]键值设为sound.start,则MyEntityGroup["sound.start"] == EntityGroup[2]
  • MyEntityGroupArray (not in Counter-Strike: Global Offensive):一个与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.pngNote:For other VScript keyvalues notable for this entity like vscripts, thinkfunction and inputs like RunScriptCode, CallScriptFunction see Generic Keyvalues, Inputs and Outputs

See also

External links