Page 1 of 2
variables with number
Posted: 15 Dec 2013 14:43
by Panda
Hey guys,
I want to set a variable with a number like :
in comming text 1 =a1
in comming text 2 =a2
in comming text 3 =a3
and so on
this is my script code but it doesn't work:
text(a) = {sms_text};
I would be happy if someone could help me

Re: variables with number
Posted: 16 Dec 2013 18:09
by Martin
Hi,
You could use a list to do this:
Code: Select all
//create an empty list
myList = newList();
//add three elements to the list
addElement(myList, "text 1");
addElement(myList, "text 2");
addElement(myList, "text 3");
//get the length of the list and store in variable n
n = length(myList);
//access the elements in the list
first_text = getElement(myList, 0);
second_text = getElement(myList, 1);
third_text = getElement(myList, 2);
There are some more functions you can use with lists such as removeElement, getRandomElement, indexOfElement etc.
Documentation is available within the app in action Script (function button) or online:
Action Script
The multiclipboard flows available in the flow sharing area use the list functions to create a list with a maximum of 5 elements:
Multiclipboard
Regards,
Martin
Re: variables with number
Posted: 17 Dec 2013 17:17
by Panda
Thx Martin

I'll try to realize your example with the list function and I'll give you a feedback if it works

Re: variables with number
Posted: 19 Dec 2013 20:51
by Panda
this part doesn't work :
addElement(text, global_sms , sms_text)
automagic doesn't accept "global_sms" and I don't know why
Re: variables with number
Posted: 19 Dec 2013 21:14
by Martin
The first parameter of the function addElement should be the list, the second parameter the element to add to the list.
I assume you want to create a list global_sms that contains the last few SMS texts. You could do this in a flow:
-trigger SMS Received
-action Script: global_sms = addElement(global_sms, sms_text)
The script will add the text contained in variable sms_text to the list. The script also creates a new list in the case when the list does not exist yet.
You might have to manually delete the variable global_sms first in case it already exists and is not a list:
-open the flow list
-press Menu->Manage->Global Variables
-select global_sms
-select Delete variable
I recommend to make an experimental flow so you don't have to send SMS to yourself:
-trigger empty
-action Script: sms_text = "test sms"
-action Script: global_sms = addElement(global_sms, sms_text)
-condititon Debug Dialog
The condition will show a dialog with all variables available in the flow and all global variables.
The list global_sms should contain one more element each time you manually execute the flow.
Re: variables with number
Posted: 20 Dec 2013 20:07
by Panda
http://automagic4android.com/flow.php?i ... 26488ee10f
this is my flow I want to create but at the top on addElement the flow stops
Re: variables with number
Posted: 22 Dec 2013 11:25
by Martin
The script fails on the third script action because it tries to add an element at index 2 to the list, which is not valid when the list only contains one element.
The index is zero based so if your list contains one element only index 0 (first position) and index 1 (second position) are valid:
Code: Select all
addElement(list, 0, sms_text); //add sms_text at the first position of the list
addElement(list, 1, sms_text); //add sms_text at the second position of the list
Re: variables with number
Posted: 22 Dec 2013 16:26
by Panda
is it possible to use a variable for the index number?
Re: variables with number
Posted: 22 Dec 2013 16:32
by Panda
http://automagic4android.com/flow.php?i ... ca8cd779a7
this is the correct version there was a mistake in the other one, but it's near the same the third scrip action is the the second action
Re: variables with number
Posted: 23 Dec 2013 19:21
by Martin
You can use a variable to add an element like this:
b=0;
addElement(list, b, sms_text);
b=1;
addElement(list, b, sms_text);
Why do you want to add elements by index? Do you want to populate the list of sms in reverse so that the last sms is stored in the first position of the list?
You could use following script to add all sms to a global list:
Code: Select all
if (global_sms_list == null)
{
global_sms_list = newList();
}
addElement(global_sms_list, sms_text);//append sms to the end of the list
//or alternatively store in reverse order
//addElement(global_sms_list, 0, sms_text);//insert sms as the first elment
b=0; //to start looping at index 0 (first element)