From The Mana World
(Blanked the page)
Line 1: Line 1:
The ''script_explode_str'' procedure (magic scripting) allows to easily get all arguments passed to a spell.


=== Code ===
{| class="wikitable"
|-
! 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)<br><br>
In the above example, the '''target''' string is split at every " " (space) and each argument is named foo'''X''' 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)

Revision as of 20:09, 5 August 2016