From The Mana World
(~~~~) |
(→Code) |
||
Line 28: | Line 28: | ||
""))))) | ""))))) | ||
|} | |} | ||
=== Example Usage === | === Example Usage === |
Revision as of 18:51, 22 November 2014
The script_explode_str procedure (magic scripting) allows to easily get all arguments passed to a spell.
Code
magic-base.sex |
---|
(PROCEDURE script_explode_str (delimiter str varname maxparams) (FOR a 0 maxparams (BLOCK (IF (< (strlen str) 1) (BREAK)) (SET arglen (strlen str)) (SET argoffset (if_then_else (contains_string str delimiter) (strstr str delimiter) arglen)) (SET arg (if_then_else (== arglen argoffset) str (substr str 0 argoffset))) (set_script_str caster (+ (+ "@" varname) (+ a "$")) arg) (SET str (if_then_else (> arglen (- argoffset 1)) (substr str (+ argoffset 1) arglen) ""))))) |
Example Usage
(CALL script_explode_str " " target "foo" 2)
In the above example, the target string is split at every " " (space) and each argument is named fooX in which X is an integer ranging from 0 to 2.
If the target string is, let's say, "hello world !" this script will make 3 arguments: @foo0$ (hello), @foo1$ (world), @foo2$ (!). These variables are then available for use in scripts or in the magic system itself (with get_script_variable)