local:moodlescript:language:freezecontext
MoodleScript: FREEZE CONTEXT
MoodleScript Script Engine
STATUS: Draft.
Effect
Freezes the execution stack context and prevents the execution of instructions from modifying it.
A number of instructions can alter the value of context variables when they execute. For example, creating a course category sets, by default, the current course category to the newly created category. A succession of category creations using the 'current' meta will create a succession of nested categories.
ADD CATEGORY My Root TO id:1
ADD CATEGORY Cat 1 TO current ADD CATEGORY Cat 2 TO current
ADD CATEGORY Cat 3 TO current
Will give the following tree:
Miscelaneous > My Root > Cat 1 > Cat 2 > Cat 3
To successively create “siblings” of the same category, the context must be frozen so that current always represents the initial category before the first addition. Thus:
ADD CATEGORY My Root TO id:1 FREEZE CONTEXT ADD CATEGORY Cat 1 TO current ADD CATEGORY Cat 2 TO current ADD CATEGORY Cat 3 TO current UNFREEZE CONTEXT
Will generate a tree like this:
- Miscelaneous
- My root
- Cat 1
- Cat 2
- Cat 3
Syntax
FREEZE CONTEXT
Specific attributes
local/moodlescript/language/freezecontext.txt · Dernière modification : de 127.0.0.1
