10 Dec 11, 10:25AM
Switch for cubescript:
[cubescript]// switch - Takes an integer argument to determine which block of code to execute.
// NOTE: This command can only handle up to 23 "cases" (24 arguments).
// SVN version only below
// switch = [
// if (&& (<= $numargs 24) (checkrange $arg1 0 22)) [
// execute (getalias (format arg%1 (+ $arg1 2)))
// ]
// ]
// AC 1104 and lower version
switch = [
if (&& (<= $numargs 24) (&& (>= $arg1 0) (<= $arg1 22))) [
tmp = (getalias (format arg%1 (+ $arg1 2)))
tmp
]
][/cubescript]
Examples:
[cubescript]i = 22
switch $i [
echo test 1 // case 0
] [
echo test 2 // case 1
] [
echo test 3 // case 2
] [
echo test 4 // case 3
] [
echo test 5 // and so on..
] [
echo test 6
] [
echo test 7
] [
echo test 8
] [
echo test 9
] [
echo test 10
] [
echo test 11
] [
echo test 12
] [
echo test 13
] [
echo test 14
] [
echo test 15
] [
echo test 16
] [
echo test 17
] [
echo test 18
] [
echo test 19
] [
echo test 20
] [
echo test 21
] [
echo test 22
] [
echo test 23
]
// Output: test 23[/cubescript]
[cubescript]bind KEY [
// Use if statements to set an integer value for switch to inspect.
//
// If editing, execute case 0 (aka switch's arg2)
// | if connected to a server, execute case 1 (aka switch's arg3)
// | | if playing bots, execute case 2 (aka switch's arg4)
// | | | else execute case 3 (aka switch's arg5)
// | | | |
if (|| $editing (= $gamemode 1)) [ i = 0 ] [ if $connected [ i = 1 ] [ if (curmodeattr bot) [ i = 2 ] [ i = 3 ] ] ]
switch $i [
echo You're editing. // case 0 code block
] [
echo You're in multiplayer. // case 1 code block
] [
echo You're in singleplayer. // case 2 code block
] [
echo You're not playing. // case 3 code block
]
]
// In SVN/future versions of AC, the above code for the keybind is a bad example. Use megabind instead.[/cubescript]
[cubescript]// switch - Takes an integer argument to determine which block of code to execute.
// NOTE: This command can only handle up to 23 "cases" (24 arguments).
// SVN version only below
// switch = [
// if (&& (<= $numargs 24) (checkrange $arg1 0 22)) [
// execute (getalias (format arg%1 (+ $arg1 2)))
// ]
// ]
// AC 1104 and lower version
switch = [
if (&& (<= $numargs 24) (&& (>= $arg1 0) (<= $arg1 22))) [
tmp = (getalias (format arg%1 (+ $arg1 2)))
tmp
]
][/cubescript]
Examples:
[cubescript]i = 22
switch $i [
echo test 1 // case 0
] [
echo test 2 // case 1
] [
echo test 3 // case 2
] [
echo test 4 // case 3
] [
echo test 5 // and so on..
] [
echo test 6
] [
echo test 7
] [
echo test 8
] [
echo test 9
] [
echo test 10
] [
echo test 11
] [
echo test 12
] [
echo test 13
] [
echo test 14
] [
echo test 15
] [
echo test 16
] [
echo test 17
] [
echo test 18
] [
echo test 19
] [
echo test 20
] [
echo test 21
] [
echo test 22
] [
echo test 23
]
// Output: test 23[/cubescript]
[cubescript]bind KEY [
// Use if statements to set an integer value for switch to inspect.
//
// If editing, execute case 0 (aka switch's arg2)
// | if connected to a server, execute case 1 (aka switch's arg3)
// | | if playing bots, execute case 2 (aka switch's arg4)
// | | | else execute case 3 (aka switch's arg5)
// | | | |
if (|| $editing (= $gamemode 1)) [ i = 0 ] [ if $connected [ i = 1 ] [ if (curmodeattr bot) [ i = 2 ] [ i = 3 ] ] ]
switch $i [
echo You're editing. // case 0 code block
] [
echo You're in multiplayer. // case 1 code block
] [
echo You're in singleplayer. // case 2 code block
] [
echo You're not playing. // case 3 code block
]
]
// In SVN/future versions of AC, the above code for the keybind is a bad example. Use megabind instead.[/cubescript]