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

Logic case: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Categorized)
 
(85 intermediate revisions by 42 users not shown)
Line 1: Line 1:
{{wrongtitle|title=logic_case}}
{{LanguageBar}}
{{TabsBar|main=s2|base=logic_case}}
{{CD|CLogicCase|file1=logicentities.cpp}}
{{this is a|logical entity|name=logic_case|sprite=1}} It compares an input to up to 16 configured values, firing a corresponding output if there is a match (on <code>InValue</code>), or fires a random output (on <code>PickRandom</code>). Use [[logic_random_outputs]] for a weighted random output.
{{Important|This entity stores values ​​as '''strings''', so if you specify one of the case as "1.50", then when you try to compare [[float]] it will not match, because the float will be "1.5", and not "1.50".}}


==Entity Description==
{{tip|Use with [[logic_timer]] for extremely random events.}}
'''Entity Name:''' logic_case
__NOTOC__
== Keyvalues ==
{{KV Targetname}}
{{KV|Case 01|to=Case 16|intn=Case01|intn2=Case16|string|The values to test against.}}


Compares an input to up to 16 preset values. If the input value is the same as any of the preset values, an output corresponding to that value is fired.
== Inputs ==
{{I|InValue|Compares the Input value converted to string to the case values, and fires the appropriate output, if any.|param=variant}}
{{I|PickRandom|param=void|Fires a random OnCase output with at least one connection.}}
{{I|PickRandomShuffle|param=void|Fires a random OnCase output with at least one connection, with no repeats until all cases have been picked, at which point the shuffle starts over.}}


For example: if Case01 is set to 2 and Case02 is set to 5, and the input value is 5, the OnCase02 output will be fired.
== Outputs ==
{{O|OnCase01|to=OnCase16|param=void|activator = activator of the input causing this|Fired when the input value equals the corresponding Case value.}}
{{O|OnDefault|param=variant|activator = activator of InValue input|Fired when the input value does not equal any of the Case values.}}
{{O|OnUsed|param=variant|activator = activator of InValue input|Fired when an input value is received, regardless of whether it matches a case. Outputs the same parameter type as was inputted with InValue input (i.e. if it was float this output will be of type float, the same applies to OnDefault output in {{mapbase}})|only={{mapbase}}}}


This entity can also be used to select from a number of random targets via the PickRandom input. One of the OnCase outputs that is connected to another entity will be picked at random and fired.
== See Also ==
 
* {{ent|logic_timer}}
==Entity Values==
* {{ent|logic_relay}}
===Keys===
* {{ent|math_counter}}
 
[[Category:IO System]]
* '''Name''' ''targetname <target_source>'' 
** The name that other entities refer to this entity by.
* '''Case 01''' ''Case01 <string>''
* '''Case 02''' ''Case02 <string>''
* '''Case 03''' ''Case03 <string>''
* '''Case 04''' ''Case04 <string>''
* '''Case 05''' ''Case05 <string>''
* '''Case 06''' ''Case06 <string>''
* '''Case 07''' ''Case07 <string>''
* '''Case 08''' ''Case08 <string>''
* '''Case 09''' ''Case01 <string>''
* '''Case 10''' ''Case01 <string>''
* '''Case 11''' ''Case01 <string>''
* '''Case 12''' ''Case01 <string>''
* '''Case 13''' ''Case01 <string>''
* '''Case 14''' ''Case01 <string>''
* '''Case 15''' ''Case01 <string>''
* '''Case 16''' ''Case01 <string>''
 
 
===Inputs===
 
* '''Kill'''
** Removes this entity from the world.
* '''KillHierarchy''' 
** Removes this entity and all its children from the world.
* '''AddOutput''' ''<output name> <targetname>:<inputname>:<parameter>:<delay>:<max times to fire (-1 == infinite)>''
** Adds an entity I/O connection to this entity. Very dangerous, use with care
* '''FireUser1'''
** Causes this entity's OnUser1 output to be fired.
* '''FireUser2'''
** Causes this entity's OnUser2 output to be fired.
* '''FireUser3'''
** Causes this entity's OnUser3 output to be fired.
* '''FireUser4'''
** Causes this entity's OnUser4 output to be fired.
* '''InValue <string>'''
** Compare the Input value to the case values, and fire the appropriate output, if any.
* '''PickRandom'''
** Fire a random OnCase output with at least one connection.
 
 
===Outputs===
 
* '''OnUser1'''
** Fired in response to FireUser1 input.
* '''OnUser2'''
** Fired in response to FireUser2 input.
* '''OnUser3'''
** Fired in response to FireUser3 input.
* '''OnUser4'''
** Fired in response to FireUser4 input.
* '''OnCase01'''
** Fired when the input value equals the Case01 value.
* '''OnCase02'''
** Fired when the input value equals the Case02 value.
* '''OnCase03'''
** Fired when the input value equals the Case03 value.
* '''OnCase04'''
** Fired when the input value equals the Case04 value.
* '''OnCase05'''
** Fired when the input value equals the Case05 value.
* '''OnCase06'''
** Fired when the input value equals the Case06 value.
* '''OnCase07'''
** Fired when the input value equals the Case07 value.
* '''OnCase08'''
** Fired when the input value equals the Case08 value.
* '''OnCase09'''
** Fired when the input value equals the Case09 value.
* '''OnCase10'''
** Fired when the input value equals the Case10 value.
* '''OnCase11'''
** Fired when the input value equals the Case11 value.
* '''OnCase12'''
** Fired when the input value equals the Case12 value.
* '''OnCase13'''
** Fired when the input value equals the Case13 value.
* '''OnCase14'''
** Fired when the input value equals the Case14 value.
* '''OnCase15'''
** Fired when the input value equals the Case15 value.
* '''OnCase16'''
** Fired when the input value equals the Case16 value.
* '''OnDefault'''
** OnDefault Fired when the input value does not equal any of the Case values.
 
==Additional Info==
* The ideal entity for if you want randomized events.
* Use with [[Logic_timer]] for extremely random events.
 
[[Category:Entities]]

Latest revision as of 10:59, 8 May 2025

English (en)中文 (zh)Translate (Translate)
C++ Class hierarchy
CLogicCase
CLogicalEntity
CServerOnlyEntity
CBaseEntity
C++ logicentities.cpp
Logic case.png

logic_case is a logical entity available in all Source Source games. It compares an input to up to 16 configured values, firing a corresponding output if there is a match (on InValue), or fires a random output (on PickRandom). Use logic_random_outputs for a weighted random output.

Icon-Important.pngImportant:This entity stores values ​​as strings, so if you specify one of the case as "1.50", then when you try to compare float it will not match, because the float will be "1.5", and not "1.50".
Tip.pngTip:Use with logic_timer for extremely random events.

Keyvalues

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

Case 01 (Case01) to Case 16 (Case16) <string>
The values to test against.

Inputs

InValue <variantRedirectInput/variant>
Compares the Input value converted to string to the case values, and fires the appropriate output, if any.
PickRandom <void>
Fires a random OnCase output with at least one connection.
PickRandomShuffle <void>
Fires a random OnCase output with at least one connection, with no repeats until all cases have been picked, at which point the shuffle starts over.

Outputs

OnCase01 to OnCase16 <void>
!activator = activator of the input causing this
!caller = this entity
Fired when the input value equals the corresponding Case value.
OnDefault <variantRedirectOutput/variant>
!activator = activator of InValue input
!caller = this entity
Fired when the input value does not equal any of the Case values.
OnUsed <variantRedirectOutput/variant> (only in Mapbase)
!activator = activator of InValue input
!caller = this entity
Fired when an input value is received, regardless of whether it matches a case. Outputs the same parameter type as was inputted with InValue input (i.e. if it was float this output will be of type float, the same applies to OnDefault output in Mapbase)

See Also