Difference between revisions of "Rule"

From Castle Wiki
m
m (Reverted edits by Maricel Ty (talk) to last revision by Ben)
Tag: Rollback
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
A Rule is a unit of logic in Castle decks. Rules can be added to [[blueprint|blueprints]] in order to change the behavior of the blueprint in response to specific events or under certain conditions.
A Rule is a unit of logic in Castle decks. Rules can be added to [[blueprint|blueprints]] in order to change the behavior of the blueprint in response to specific events or under certain conditions.
[[File:Golf-ball-rules.jpg|alt=A screenshot of a blueprint in the Castle editor showing several Rules|thumb|An example of a blueprint containing several rules.]]
Each rule consists of a [[Trigger]] and one or more [[response|Responses]]. A trigger is the part of a Rule that describes when to run that rule, such as '''When this is tapped'''. Responses are the part of the rule that describe what to do after the rule is triggered, such as '''Destroy this actor'''. A blueprint can have many rules, but it doesn't have to have any.


Each rule consists of a [[Trigger]] and one or more [[response|Responses]]. Examples of a trigger include '''When this is tapped''' and '''When this collides'''. There are many different responses, but some examples include: '''Move toward another actor''', '''Set the value of a variable''', '''Create another actor''', and '''Destroy this actor'''.
There are many different possible triggers and even more responses. Simple rules can be used by anybody to add basic logic to a game or a piece of art, like playing a sound effect when the player taps an item, or restarting the card when the player [[Collision|collides]] with an enemy. When rules start to get more complex, they can do almost anything. Advanced users have used them to make procedural art, simulations, and even basic 3d games. Rules are one of the most powerful core elements of Castle.


== Adding and editing rules ==
To add rules to blueprints, first open the [[Inspector]] for the blueprint you'd like to edit, then go to the [[Logic]] tab.
To add rules to blueprints, first open the [[Inspector]] for the blueprint you'd like to edit, then go to the [[Logic]] tab.
== Learning how to write rules ==
The best way to learn Rules is to follow a guide, such as [[Guides:How to make your first Castle deck|How to make your first Castle deck]], which walks you through making your first Rules. Secondly, consider starting with one of the premade Castle [[Kits]], and then inspect the blueprints that come with it. Lastly, you can also [[View Source|View the Source]] of any deck to see how it was made.
== Examples of rules ==
As an illustrative example, imagine a golf game. You want to be able to sling the golf ball when it's sitting on the ground, but after it's flying through the air, the player shouldn't be able to sling it anymore. The golf ball might have a rule like this:
When this is slung: Disable behavior slingshot
Eventually, after the ball reaches the ground and comes to a stop, we want to allow the player to sling again:
When this stops moving: Enable behavior slingshot
If the player accidentally slings the ball out of the screen, we count that as losing the game, so we want to start the level over. The golf ball might have a third rule like this one:
When this exits the camera viewport: Restart this card
But if the player succeeds in putting the golf ball in the hole, we want to show a message saying they won:
When this collides with tag #hole: Create text box "You got the ball into the hole!"
You can find a (slightly more complex) version of these exact rules if you check out the [[Golf Course Kit]].

Latest revision as of 19:53, 1 August 2022

A Rule is a unit of logic in Castle decks. Rules can be added to blueprints in order to change the behavior of the blueprint in response to specific events or under certain conditions.

A screenshot of a blueprint in the Castle editor showing several Rules
An example of a blueprint containing several rules.

Each rule consists of a Trigger and one or more Responses. A trigger is the part of a Rule that describes when to run that rule, such as When this is tapped. Responses are the part of the rule that describe what to do after the rule is triggered, such as Destroy this actor. A blueprint can have many rules, but it doesn't have to have any.

There are many different possible triggers and even more responses. Simple rules can be used by anybody to add basic logic to a game or a piece of art, like playing a sound effect when the player taps an item, or restarting the card when the player collides with an enemy. When rules start to get more complex, they can do almost anything. Advanced users have used them to make procedural art, simulations, and even basic 3d games. Rules are one of the most powerful core elements of Castle.

Adding and editing rules

To add rules to blueprints, first open the Inspector for the blueprint you'd like to edit, then go to the Logic tab.

Learning how to write rules

The best way to learn Rules is to follow a guide, such as How to make your first Castle deck, which walks you through making your first Rules. Secondly, consider starting with one of the premade Castle Kits, and then inspect the blueprints that come with it. Lastly, you can also View the Source of any deck to see how it was made.

Examples of rules

As an illustrative example, imagine a golf game. You want to be able to sling the golf ball when it's sitting on the ground, but after it's flying through the air, the player shouldn't be able to sling it anymore. The golf ball might have a rule like this:

When this is slung: Disable behavior slingshot

Eventually, after the ball reaches the ground and comes to a stop, we want to allow the player to sling again:

When this stops moving: Enable behavior slingshot

If the player accidentally slings the ball out of the screen, we count that as losing the game, so we want to start the level over. The golf ball might have a third rule like this one:

When this exits the camera viewport: Restart this card

But if the player succeeds in putting the golf ball in the hole, we want to show a message saying they won:

When this collides with tag #hole: Create text box "You got the ball into the hole!"

You can find a (slightly more complex) version of these exact rules if you check out the Golf Course Kit.