Engine:CCMD run: Difference between revisions
Jump to navigation
Jump to search
Line 16: | Line 16: | ||
This very basic syntax structure however lends well to being flexible and extensible, and thus sometimes confusing. A complex base Engine script can interact with many different environments and contexts. | This very basic syntax structure however lends well to being flexible and extensible, and thus sometimes confusing. A complex base Engine script can interact with many different environments and contexts. | ||
An example test script named 'startup.cfg' can look like: | |||
<kua> | <kua> | ||
context global | context global |
Revision as of 19:22, 15 October 2023
Load and run script file. Run a named script file. Name must include extension.
run startup.cfg
Arguments
- name - The name of the script file to load and run.
Associations
- Is by default placed in the 'global' context.
Details
The word "script" can be a very loose term in general, with lots of meanings. Here it can be even more confusing.
In Engine, the most basic type of script is comprised of a core set of facilities in the Data module, which are composed of vars, cmds, aliases, binds, and contexts, with a very basic syntax.
This very basic syntax structure however lends well to being flexible and extensible, and thus sometimes confusing. A complex base Engine script can interact with many different environments and contexts.
An example test script named 'startup.cfg' can look like:
context global
bind Y "run startup.cfg" // reload this file
alias testscript '
context lua
{
print("Lua")
local s = ""
for i = 10, 1, -1 do
s = s .. i .. " "
end
io.write(s)
}
exit
context js
{
print("JavaScript");
var s = "";
for (i = 10; i >= 1; i--) s += i + " ";
print(s);
}
exit
'
bind U testscript
Examples
Default values
For a script file named 'startup.cfg' and looks like:
echo fred
lua print(1 + 3)
alias bob fred
var fred james
bob
- Try to load a non-existent file.
> run bob.cfg Run failed: bob.cfg
- Run the example script file.
> run startup.cfg
fred
4
'fred' is 'james'
- In this case: echos 'fred' to console, runs a Lua statement that adds '1 + 3' and prints the result, creates an alias 'bob', creates 'fred' variable that the alias 'bob' will show the value of, runs the 'bob' alias that effectively prints the value of 'fred' that is 'james'.