Changes

Jump to navigation Jump to search
integrate sections into new page
Line 5: Line 5:  
This page documents '''game state queries''', a built-in way to specify conditions in some of the game's data assets.
 
This page documents '''game state queries''', a built-in way to specify conditions in some of the game's data assets.
   −
==From migration guide==
+
==Overview==
 
A ''game state query'' is a vanilla way to specify conditions for some content like [[#Custom shops|shop data]], inspired by [[Modding:Content Patcher|Content Patcher]]'s conditions. A query consists of a comma-delimited list of conditions in the form {{t|type}} {{o|arguments}}. The type can be prefixed with <code>!</code> to negate it. The query is true if it's null/blank, or if every listed condition exists and is true. For example, <code>!SEASON Spring, WEATHER Here Sun</code> is true on sunny non-[[spring]] days.
 
A ''game state query'' is a vanilla way to specify conditions for some content like [[#Custom shops|shop data]], inspired by [[Modding:Content Patcher|Content Patcher]]'s conditions. A query consists of a comma-delimited list of conditions in the form {{t|type}} {{o|arguments}}. The type can be prefixed with <code>!</code> to negate it. The query is true if it's null/blank, or if every listed condition exists and is true. For example, <code>!SEASON Spring, WEATHER Here Sun</code> is true on sunny non-[[spring]] days.
   Line 15: Line 15:  
You can add quotes to keep spaces within an argument. For example, <code>BUILDINGS_CONSTRUCTED Here "Junimo Hut"</code> passes <code>Junimo Hut</code> as one argument. You can escape inner quotes with backslashes like <code>ANY "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. Remember that quotes and backslashes inside JSON strings need to be escaped too, like <code>"Condition": "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>.
 
You can add quotes to keep spaces within an argument. For example, <code>BUILDINGS_CONSTRUCTED Here "Junimo Hut"</code> passes <code>Junimo Hut</code> as one argument. You can escape inner quotes with backslashes like <code>ANY "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>. Remember that quotes and backslashes inside JSON strings need to be escaped too, like <code>"Condition": "BUILDINGS_CONSTRUCTED Here \"Junimo Hut\""</code>.
   −
====Conditions====
+
==Built-in queries==
<dl>
+
===Meta===
<dt>Meta</dt>
  −
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 27: Line 25:  
| Get whether at least one of the listed game state queries match, where each argument is a query. For example, <code>ANY "SEASON Winter" "SEASON Spring, DAY_OF_WEEK Friday"</code> is true if (a) it's winter or (b) it's a spring Friday. You can list any number of queries to check.
 
| Get whether at least one of the listed game state queries match, where each argument is a query. For example, <code>ANY "SEASON Winter" "SEASON Spring, DAY_OF_WEEK Friday"</code> is true if (a) it's winter or (b) it's a spring Friday. You can list any number of queries to check.
 
|}
 
|}
</dd>
     −
<dt>Date & time</dt>
+
===Date & time===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 66: Line 62:  
| Whether the current year is between {{t|min}} and {{o|max}} (default unlimited) inclusively.
 
| Whether the current year is between {{t|min}} and {{o|max}} (default unlimited) inclusively.
 
|}
 
|}
</dd>
     −
<dt>Events</dt>
+
===Events===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 78: Line 72:  
| Whether one of the the given [[Modding:Event data|event]] IDs are currently playing.
 
| Whether one of the the given [[Modding:Event data|event]] IDs are currently playing.
 
|}
 
|}
</dd>
     −
<dt>World</dt>
+
===World===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 219: Line 211:  
| Whether any world state flag with the given {{t|id}} is set.
 
| Whether any world state flag with the given {{t|id}} is set.
 
|}
 
|}
</dd>
     −
<dt>Player info & progress</dt>
+
===Player info & progress===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 387: Line 377:  
* <samp>weedsEliminated</samp>.
 
* <samp>weedsEliminated</samp>.
 
|}
 
|}
</dd>
     −
<dt>Player relationships</dt>
+
===Player relationships===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 417: Line 405:  
| Whether the preferred pet for the [[#Target player|specified player(s)]] is <samp>Cat</samp>, <samp>Dog</samp>, or a specified custom pet type.
 
| Whether the preferred pet for the [[#Target player|specified player(s)]] is <samp>Cat</samp>, <samp>Dog</samp>, or a specified custom pet type.
 
|}
 
|}
</dd>
     −
<dt>Randomization</dt>
+
===Randomization===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 448: Line 434:  
| A specialized variant of <samp>SYNCED_DAY_RANDOM</samp> used to calculate the chance of rain in summer, which increases with the day number.
 
| A specialized variant of <samp>SYNCED_DAY_RANDOM</samp> used to calculate the chance of rain in summer, which increases with the day number.
 
|}
 
|}
</dd>
     −
<dt>For items only</dt>
+
===For items only===
<dd>
   
These queries apply in cases where there's an item (e.g. machine recipes, shops, etc); they'll return false if not applicable. They take a {{t|type}} argument which can be <samp>Input</samp> (the machine input item) or <samp>Target</samp> (the machine output, tree fruit, shop item, etc).
 
These queries apply in cases where there's an item (e.g. machine recipes, shops, etc); they'll return false if not applicable. They take a {{t|type}} argument which can be <samp>Input</samp> (the machine input item) or <samp>Target</samp> (the machine output, tree fruit, shop item, etc).
   Line 477: Line 461:  
| Whether the [[#Custom items|item's type definition ID]] matches the given value. For example, <samp>ITEM_TYPE Target (BC)</samp> matches bigcraftables.
 
| Whether the [[#Custom items|item's type definition ID]] matches the given value. For example, <samp>ITEM_TYPE Target (BC)</samp> matches bigcraftables.
 
|}
 
|}
</dd>
     −
<dt>Immutable</dt>
+
===Immutable===
<dd>
   
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 492: Line 474:  
| A condition which never matches.
 
| A condition which never matches.
 
|}
 
|}
</dd>
  −
</dl>
     −
====Target location====
+
==Common values==
 +
===Target location===
 
Some conditions have a {{t|location}} argument. This can be one of...
 
Some conditions have a {{t|location}} argument. This can be one of...
 
{| class="wikitable"
 
{| class="wikitable"
Line 514: Line 495:  
|}
 
|}
   −
====Target player====
+
===Target player===
 
Some conditions have a {{t|player}} argument. This can be one of...
 
Some conditions have a {{t|player}} argument. This can be one of...
 
{| class="wikitable"
 
{| class="wikitable"
Line 560: Line 541:  
|}
 
|}
   −
====Using queries elsewhere====
+
==For C# mod authors==
 +
===Using queries elsewhere===
 
C# code can use the <samp>GameStateQuery</samp> class to work with queries, like <code>GameStateQuery.CheckConditions(query)</code>.
 
C# code can use the <samp>GameStateQuery</samp> class to work with queries, like <code>GameStateQuery.CheckConditions(query)</code>.
    
You can also use game state queries in [[Modding:Event data|event preconditions]] using the new <samp>G</samp> condition flag, like <code>some_event_id/G !SEASON Spring, WEATHER Here Sun</code>.
 
You can also use game state queries in [[Modding:Event data|event preconditions]] using the new <samp>G</samp> condition flag, like <code>some_event_id/G !SEASON Spring, WEATHER Here Sun</code>.
   −
====Extensibility====
+
===Extensibility===
 
C# mods can check if a query exists using <code>GameStateQuery.Exists("Example.ModId_ConditionName")</code>, and define custom conditions using <code>GameStateQuery.Register("Example.ModId_ConditionName", handleQueryMethod)</code>. To avoid conflicts, prefixing custom condition names with your mod ID is strongly recommended.
 
C# mods can check if a query exists using <code>GameStateQuery.Exists("Example.ModId_ConditionName")</code>, and define custom conditions using <code>GameStateQuery.Register("Example.ModId_ConditionName", handleQueryMethod)</code>. To avoid conflicts, prefixing custom condition names with your mod ID is strongly recommended.
      
[[Category:Modding]]
 
[[Category:Modding]]
translators
8,439

edits

Navigation menu