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;
dynamic variables
Moderator: Martin
Re: dynamic variables
Hi, Newturn.
You can create a map with newMap() for this, check the docs for action script and script examples.
Regards,
Hal
You can create a map with newMap() for this, check the docs for action script and script examples.
Regards,
Hal
Re: dynamic variables
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.
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.
-
- Posts: 109
- Joined: 16 Apr 2014 04:57
Re: dynamic variables
Hey newturn!
Do let me know if you get lucky creating dynamic variable names.
Thanks
Akhilesh
Do let me know if you get lucky creating dynamic variable names.
Thanks
Akhilesh
Re: dynamic variables
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.
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.
Re: dynamic variables
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.

Hope someone can give me any hint for compacting the code. It's much to write!!!
Following works.
Re: dynamic variables
Hi,
The variables reference the maps but assigning something to a reference does not automatically add it to the "parent" map:
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:
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:
Regards,
Martin
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;
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;
Code: Select all
wlanmap["cellids"][cid] = now;
wlanmap["celllacids"][lac] = now;
wlanmap["cellpscids"][psc] = now;
Martin
Re: dynamic variables
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.
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
