You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ahref="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/script-id-mapping.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
150
+
<ahref="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Migration/guides.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
<h1id="script-id-mapping"><aclass="header" href="#script-id-mapping">Script ID mapping</a></h1>
185
-
<p>Every script is currently identified by a unique ID.</p>
186
-
<p>ID's are derived from the script asset path for scripts loaded via the asset system.</p>
187
-
<p>By default this is an identity mapping, but you can override this by modifying the <code>AssetPathToScriptIdMapper</code> inside the <code>ScriptAssetSettings</code> resource before loading the script.</p>
188
-
<divclass="warning">
189
-
Be wary of path separators, by default script ID's are derived from asset paths, which are platform dependent. Make sure to use `std::path::PathBuf` if you are targetting multiple platforms.
<ahref="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/sharing-contexts-between-scripts.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
150
+
<ahref="https://github.com/makspll/bevy_mod_scripting/edit/main/docs/src/Summary/contexts.md" title="Suggest an edit" aria-label="Suggest an edit" rel="edit">
<p>By default BMS will create an individual script context, or sandbox, for each script that is run. This means that each script will have its own set of global variables and functions that are isolated from other scripts. However, sometimes this might not be desirable, if you aren't worried about scripts interfering with each other, or if you want to easilly share data between scripts. In these cases, you can use shared contexts.</p>
<p>Each script runs in a context. By default BMS will create an individual context, or sandbox, for each script-entity pair that is run. This means that each script-entity pair will have its own set of global variables and functions that are isolated from other scripts. However, sometimes this might not be desirable. If you are not worried about scripts interfering with each other, or if you want to easily share data between scripts, you can consider using a different context policy.</p>
<p>A shared context means that all scripts run in the same context; there is in fact only one context to run in. If the scripts interact heavily with each other, this may be what you want.</p>
189
+
<p>To enable a shared context, set the corresponding context policy on the scripting plugin:</p>
A per script context provides each script with their own context. However, scripts may be attached to multiple entities, in which case a single script context is shared by multiple entities.
196
+
197
+
To enable per script contexts, insert the `ContextPolicy::per_script()` resource.
<p>we read <code>policy_b</code> like this: if <code>ContextKey</code> has a script, return a <code>ContextKey</code> with only a script. Failing that <code>ContextRule::Shared</code> always returns an empty <code>ContextKey</code>.</p>
231
+
<p>One may also provide an entirely custom rule by implementing the <code>ContextKeySelector</code> trait.</p>
<p>All context loading settings are stored in a separate resource per scripting plugin namely: <code>ContextLoadingSettings<Plugin></code>.</p>
193
234
<p>The settings are as follows:</p>
194
235
<ul>
195
236
<li><code>loader</code> - the load and unload strategy for contexts. Each scripting plugin will have a load and unload function which is hooked up through here</li>
196
-
<li><code>assigner</code> - the strategy for assigning/unassigning contexts to scripts. This is used to determine how to assign a context to a script when it is run, and what to do with the context when the script is finished.</li>
197
237
<li><code>context_initializers</code> - stores all context initializers for the plugin</li>
198
238
<li><code>context_pre_handling_initializers</code> - stores all context pre-handling initializers for the plugin</li>
0 commit comments