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
No edit summary
 
(26 intermediate revisions by 16 users not shown)
Line 1: Line 1:
{{base point|logic_case}}
{{LanguageBar}}
 
{{TabsBar|main=s2|base=logic_case}}
==Entity description==
{{CD|CLogicCase|file1=logicentities.cpp}}
[[File:logic_case.png|left|link=]]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.
{{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".}}
{{bug|This entity will not recognize [[float]]s with trailing zeroes (like <code>0.50</code> or <code>1.00</code>). Always remove any.}}


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


== Inputs ==
== Inputs ==
{{IO|InValue|Compares the Input value to the case values, and fires the appropriate output, if any.|param=string}}
{{I|InValue|Compares the Input value converted to string to the case values, and fires the appropriate output, if any.|param=variant}}
{{IO|PickRandom|Fires a random OnCase output with at least one connection.}}
{{I|PickRandom|param=void|Fires a random OnCase output with at least one connection.}}
{{IO|PickRandomShuffle|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.}}
{{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.}}
{{I Targetname}}


== Outputs ==
== Outputs ==
{{IO|OnCase01|to=OnCase16|Fired when the input value equals the corresponding Case value.}}
{{O|OnCase01|to=OnCase16|param=void|activator = activator of the input causing this|Fired when the input value equals the corresponding Case value.}}
{{IO|OnDefault|Fired when the input value does not equal any of the Case values.}}
{{O|OnDefault|param=variant|activator = activator of InValue input|Fired when the input value does not equal any of the Case values.}}
{{O Targetname}}
{{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}}}}
 
==Tutorials about Logic_Case (Russian)==
Lessons created by [https://vk.com/project_source Project-S]


*[https://www.youtube.com/watch?v=RFpyUdxQpkA Logic_Case make random (на Русском)]
== See Also ==
* {{ent|logic_timer}}
* {{ent|logic_relay}}
* {{ent|math_counter}}
[[Category:IO System]]

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