Attribute Chaining Rules
In 3D Basic, you can connect several attributes to an object using dot notation. It is common to use one or two attributes in sequence, but in some cases, three attributes can also be used.
There is therefore no fixed limit of two attributes. However, very long attribute chains should be avoided, as they can make the code difficult to read and may indicate that something has been written incorrectly.
--------------------------------------------------------------------------------------------------
Number of Attributes
An object can normally have one or two attributes in sequence. There are also situations where three attributes are valid.
Syntax:
ObjectName.attribute1.attribute2 = value/literal
or:
ObjectName.attribute1.attribute2.attribute3 = value/literal
Three attributes are therefore allowed, but are less common.
If an attribute chain starts to contain more than three attributes, there is a possibility that the code has not been written as intended. It is therefore a good idea to check the code whenever a chain becomes longer than three attributes.
--------------------------------------------------------------------------------------------------
Using Surface Names
You can also target a specific surface of an object:
ObjectName.surfaceName.attribute1.attribute2 = value/literal
Here, surfaceName does not count as an attribute. It simply identifies which part of the object the attributes should affect. This means that a surface name can be followed by the same type of attribute chain as a regular object.
Examples:
box1.b1.color = red
or:
box1.b1.image.rotate = 90
--------------------------------------------------------------------------------------------------
Why Should Long Attribute Chains Be Avoided?
Even though 3D Basic allows three attributes in certain situations, it is unusual to need very long attribute chains.
Short chains have several advantages:
• The code is easier to read
• It is easier to understand what each attribute does
• The risk of using an incorrect combination is reduced
• It is easier to find errors in the code
If an object needs many different properties, it is therefore usually better to write them on separate lines rather than trying to put everything into the same chain.
--------------------------------------------------------------------------------------------------
Important Rule
The fact that several attributes can be combined does not mean that all attributes can be combined with each other.
3D Basic has certain predefined combinations where the attributes work together. Other combinations may be invalid or have no meaningful effect.
So, both the number of attributes and which attributes are combined determine whether an attribute chain is valid.
--------------------------------------------------------------------------------------------------
Valid Example
box1.animate.rotate = (0,0,0) to (0,360,0)
Here, animate is used together with rotate. This is a valid combination used to create a rotating animation.
--------------------------------------------------------------------------------------------------
Three Attributes
Three attributes can occur in certain valid combinations.
Example:
ObjectName.attribute1.attribute2.attribute3 = value/literal
Three attributes are less common than one or two attributes and should only be used when the combination has a clear function in the language.
--------------------------------------------------------------------------------------------------
Be Careful with Very Long Chains
A chain with more than three attributes is not automatically proof that something is wrong, but it is a clear signal that the code should be checked.
--------------------------------------------------------------------------------------------------
Example:
box1.size.color.move.animate = ...
When a chain becomes this long, it is easy to accidentally combine attributes that do not belong together or to write the attributes in the wrong order.
In such cases, it is usually better to split the code into several lines.
--------------------------------------------------------------------------------------------------
A Clearer Way
Instead, write the properties on separate lines:
10 box1.size = (2,2,2)
20 box1.color = red
30 box1.move = (0,1,0)
40 box1.animate = (0,0,0) to (5,0,0)
50 box1.draw
This makes the code clearer, easier to read, and easier to debug.
--------------------------------------------------------------------------------------------------
Summary
• One or two attributes are the most common.
• Three attributes can occur in valid combinations.
• More than three attributes should be seen as a signal to check the code.
• Not all attributes can be combined with each other.
• When many properties need to be specified, several separate lines are usually the clearest approach.