[CMD][VE] ForEach - for visual editor

stable
By Strooth in Miscellaneous Published May 2021 👁 1,531 views 💬 1 comments

Description

I see lots of people asking if they can do for each loops in visual editor. This should sort of help, but not great. You need to know the parameters exactly and supply the command as text. You probably shouldn't be using this and don't really recommend that you do but here it is anyway.
HaasScript
-- Author: [email protected]
DefineCommand('ForEach', 'ForEach Loop for Visual Editor')

local cmd = DefineParameter(StringType, 'Command', 'The Command to run', true, 'IsOrderOpen', 'IsOrderOpen')
local list = DefineParameter(ListDynamicType, 'List', 'The list items to process', false, {'test'}, 'Array, List')
local params = DefineParameter(ListDynamicType, 'Params', 'The Parameters of the command, IN CORRECT ORDER!', false, 'none', 'input, list')

local cmd = GetCommand(cmd)
local results = {}
for i=1, #list do 
    local object = list[i]
    results[i] = cmd(Parse(StringJoin(object, params), StringType))
end 

DefineOutput(ListDynamicType, results, 'the results from each command run')

1 Comment

Sign in to leave a comment.

J
jsoriano almost 4 years ago

Hello. Would it be possible to use this command to get the next number in a list? starting with 1 each time a condition occurs add 1. thanks. The idea is use multiple positions.