dynamic variables

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
newturn
Posts: 30
Joined: 20 Apr 2016 08:36

dynamic variables

Post by newturn » 21 May 2016 20:11

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;

Hal
Posts: 3
Joined: 21 May 2016 19:18

Re: dynamic variables

Post by Hal » 21 May 2016 20:24

Hi, Newturn.

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

Regards,
Hal

User avatar
Bushmills
Posts: 286
Joined: 23 Sep 2014 21:56

Re: dynamic variables

Post by Bushmills » 22 May 2016 12:36

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.

akhileshg1988
Posts: 109
Joined: 16 Apr 2014 04:57

Re: dynamic variables

Post by akhileshg1988 » 23 Aug 2016 16:44

Hey newturn!
Do let me know if you get lucky creating dynamic variable names.

Thanks
Akhilesh

newturn
Posts: 30
Joined: 20 Apr 2016 08:36

Re: dynamic variables

Post by newturn » 01 Oct 2016 11:00

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 22967 times
snap083.jpg
snap083.jpg (2.65 KiB) Viewed 22967 times
snap084.jpg
snap084.jpg (35.92 KiB) Viewed 22967 times

newturn
Posts: 30
Joined: 20 Apr 2016 08:36

Re: dynamic variables

Post by newturn » 01 Oct 2016 11:23

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 22964 times

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: dynamic variables

Post by Martin » 01 Oct 2016 12:53

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

newturn
Posts: 30
Joined: 20 Apr 2016 08:36

Re: dynamic variables

Post by newturn » 01 Oct 2016 15:02

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.

Post Reply