Page 1 of 1

dynamic variables

Posted: 21 May 2016 20:11
by newturn
Hi there,

is it possible to create dynamic variable names?

For example i want to save received messages into an array. But i am unsure how to track the different contents for it.

Say i receive some sms messages. I know i can add those ones to an list. But how to keep track from who this message was send? Should i add the new item to the list like this?

"the message::the sender"

any hints how to track different arrays which are associated with each other? example:

listmessages;
listsenders;

Re: dynamic variables

Posted: 21 May 2016 20:24
by Hal
Hi, Newturn.

You can create a map with newMap() for this, check the docs for action script and script examples.

Regards,
Hal

Re: dynamic variables

Posted: 22 May 2016 12:36
by Bushmills
Also, "dynamic" variables as I seem to understand you're thinking of (as in, not specifying a variable name literally, but, say, a variable containing the name of another variable, akin to "variable indirection"), are possible. Functions getValue and setValue allow specifying the variable name as literal (in quotes), as such an indirection variable (no quotes), or even as result of a function or operation.

Example script action:
foo = "Share and enjoy (c) Sirius Cybernetics Corp";
var1 = "foo";
var2 = "bar";
setValue(var2, getValue(var1, "default if undefined"));

variable bar should now contain the text from variable foo.

Re: dynamic variables

Posted: 23 Aug 2016 16:44
by akhileshg1988
Hey newturn!
Do let me know if you get lucky creating dynamic variable names.

Thanks
Akhilesh

Re: dynamic variables

Posted: 01 Oct 2016 11:00
by newturn
hi there,

first thanksall for responding!!

I am trying currently to work on it again. But somehow it is frustrating. So i always abort my projects :(

I don't understand why my map is empty? What is wrong, or is my logic right but automagic scripting isn't so much extended? The debug window shows all is right.
snap082.jpg
snap082.jpg (25.48 KiB) Viewed 22986 times
snap083.jpg
snap083.jpg (2.65 KiB) Viewed 22986 times
snap084.jpg
snap084.jpg (35.92 KiB) Viewed 22986 times

Re: dynamic variables

Posted: 01 Oct 2016 11:23
by newturn
So i guess referencing is not possible. It seems the values are copied :(

Hope someone can give me any hint for compacting the code. It's much to write!!!

Following works.
snap086.jpg
snap086.jpg (42.43 KiB) Viewed 22983 times

Re: dynamic variables

Posted: 01 Oct 2016 12:53
by Martin
Hi,

The variables reference the maps but assigning something to a reference does not automatically add it to the "parent" map:

Code: Select all

wlanmap = global_map[wlan];
if(wlanmap==null) {wlanmap=newMap();} // this line does not automatically add the wlanmap to global_map[wlan]

// required code to add wlanmap to global_map
global_map[wlan] = wlanmap;
You could also use function addMapEntry to add something to a map. I just used the assignment syntax to make the script a bit shorter.
I used ==null to check if a map is already available, isEmpty also evaluates to true when the map is defined but does not contain any values which is not necessary in your case.

Following could work:

Code: Select all

if (global_cellnearmap == null) { global_cellnearmap = newMap(); }

wlanmap = global_cellnearmap[global_wlanconnectedname];
if (wlanmap == null)
{
  wlanmap = newMap();
  global_cellnearmap[global_wlanconnectedname] = wlanmap;

  wlanmap["cellids"] = newMap();
  wlanmap["celllacids"] = newMap();
  wlanmap["cellpscids"] = newMap();
}

now = getDate();
wlanmap["cellids"][now] = cid;
wlanmap["celllacids"][now] = lac;
wlanmap["cellpscids"][now] = psc;
I'm not sure if you want to store the last time that a cell was in use or if you want to store the history of all encountered cells. Maybe you have to replace the last three lines by this:

Code: Select all

wlanmap["cellids"][cid] = now;
wlanmap["celllacids"][lac] = now;
wlanmap["cellpscids"][psc] = now;
Regards,
Martin

Re: dynamic variables

Posted: 01 Oct 2016 15:02
by newturn
Thanks Martin.

Very much appreciated the fast response :)

I will try to implement it.

i tried some shortenings and found out most doesn't work. for example:
if(global_wlan == null) { newMap(); } or if(global_wlan == null) { = newMap(); } doesn't work

Maybe you can add some shorthands to automagic scripting. Most time decisions are made. So, IIF or something like that would come handy :) especially on a small screen and keyboard.