Limit put keys of array to first level?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Limit put keys of array to first level?
I have a multidimensional array and need to list only the items in the first level.
Here's the overview of the array
channels[channelname][messages]
so for example channels["bobs channel"]["firstmessage\NLsecondmessage\NLetc"]
channels["lucys channel"]["firstmessage\NLsecondmessage\NLetc"]
put the keys of channels works but displays both channelnames and messages, is there a simple way of limiting this so it only spits out the channelname?
Here's the overview of the array
channels[channelname][messages]
so for example channels["bobs channel"]["firstmessage\NLsecondmessage\NLetc"]
channels["lucys channel"]["firstmessage\NLsecondmessage\NLetc"]
put the keys of channels works but displays both channelnames and messages, is there a simple way of limiting this so it only spits out the channelname?
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Limit put keys of array to first level?
Hi.
You can always massage the data in the clear. Combine the array variable with, say, return and tab. Set the itemDel to tab, and then extract the second item in each line of the (now ordinary) new variable into a return delimited list, or whatever.
Craig Newman
You can always massage the data in the clear. Combine the array variable with, say, return and tab. Set the itemDel to tab, and then extract the second item in each line of the (now ordinary) new variable into a return delimited list, or whatever.
Craig Newman
Re: Limit put keys of array to first level?
That doesn't seem to play nice with the multidimensional array.
I was getting a bunch of blank lines, and only one result, so I tried with a simple test and when it's a multidimensional array it doesn't work right.
I tried:
The above works fine, but this does not:
I was getting a bunch of blank lines, and only one result, so I tried with a simple test and when it's a multidimensional array it doesn't work right.
I tried:
Code: Select all
put "stuff1" into bob["bob"]
put "stuff2" into bob["bob2"]
combine bob with ","
put Bob
Code: Select all
put "stuff1" into bob["bob"]["messages"]
put "stuff2" into bob["bob2"]["messages"]
combine bob with ","
put Bob
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Limit put keys of array to first level?
Funny just posted this.
http://forums.runrev.com/phpBB2/viewtop ... =7&t=19331
You would change to ["channelname"]
Simon
http://forums.runrev.com/phpBB2/viewtop ... =7&t=19331
You would change to ["channelname"]
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit put keys of array to first level?
I'm sorry, but I don't understand how that would help me.
I'm not pulling the data from a datagrid, so I can't use dgIndexes.
Assume that "bobs channel" and "lucys channel" are unknown names.
It can't be this hard to just pull all the first keys from an array, it's driving me insane. lol
All I need to figure out at this stage is how to get all the values of the first keys of channel[][]
I'm not pulling the data from a datagrid, so I can't use dgIndexes.
Assume that "bobs channel" and "lucys channel" are unknown names.
It can't be this hard to just pull all the first keys from an array, it's driving me insane. lol
All I need to figure out at this stage is how to get all the values of the first keys of channel[][]
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Limit put keys of array to first level?
Hi sorry, but you see theDataA is a multi-dimentional array
Ahh...
There does that help?
Simon
Ahh...
Code: Select all
repeat for each key tKey in theDataA
put theDataA[tKey]["channelname"] & cr after tNames
end repeat
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit put keys of array to first level?
To a point, there's a misunderstanding, it's likely due to my stupid naming-scheme.
I'm dynamically creating keys in the array based on user input basically like this;
User joins channel "bobs cooking", so a new value for the channel array is created and looks like this: put "bobs cooking" into channel["bobs cooking"]
Subsequent messages from that channel are put into the array like this: put "the message text" into channel[currentChannel]["messages"]
Where currentChannel is, well the current channel the user is chatting on.
I was under the assumption that I would easily be able to retrieve only the first keys in order to create a list of channels.
I'm dynamically creating keys in the array based on user input basically like this;
User joins channel "bobs cooking", so a new value for the channel array is created and looks like this: put "bobs cooking" into channel["bobs cooking"]
Subsequent messages from that channel are put into the array like this: put "the message text" into channel[currentChannel]["messages"]
Where currentChannel is, well the current channel the user is chatting on.
I was under the assumption that I would easily be able to retrieve only the first keys in order to create a list of channels.
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Limit put keys of array to first level?
Hi Marcus,
Easier still
Did I get the array right?
Simon
Edit: I see I could do without the " put "bobs cooking" into channel["bobs cooking"]" part.
Easier still
Code: Select all
on mouseUp
put "bobs cooking" into channel["bobs cooking"]
put "the message text" into channel["bobs cooking"]["messages"]
put "sue cooking" into channel["sue cooking"]
put "the message text" into channel["sue cooking"]["messages"]
put "tom cooking" into channel["tom cooking"]
put "the message text" into channel["tom cooking"]["messages"]
repeat for each key tKey in channel
put tKey & cr after tChannel
end repeat
end mouseUp
Simon
Edit: I see I could do without the " put "bobs cooking" into channel["bobs cooking"]" part.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Limit put keys of array to first level?
See? I KNEW there had to be a simple way
Thanks, Simon, if we ever meet I owe you a handful of beers by now. lol
Thanks, Simon, if we ever meet I owe you a handful of beers by now. lol
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Limit put keys of array to first level?
I'm not seeing that, the keys of a test array return only the first level. I have an array like this:trenatos wrote:put the keys of channels works but displays both channelnames and messages, is there a simple way of limiting this so it only spits out the channelname?
Code: Select all
PeopleArray
Person1
First name
Last name
DOB
Person2
First name
Last name
DOB
Person1
Person2
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Limit put keys of array to first level?
He was trying to get deeper "levels" of an array.
This lists the third nesting (the "Z"), key by key. But defined by the hard wired "3" and "4" in the first and second levels.
I think. Anyway, Simon seems to have hit a chord.
Craig
Code: Select all
on mouseUp
repeat with x=1 to 10
repeat with y=1 to 10
repeat with z=1 to 10
put random(433) into myArray[x][y][z]
end repeat
end repeat
end repeat
repeat for each key tKey in myArray
put myArray[tKey][3][4] & return after tResults
end repeat
answer tResults
end mouseUp
I think. Anyway, Simon seems to have hit a chord.
Craig
Re: Limit put keys of array to first level?
Yes, I have a multidimensional array with an "unknown" first key (It's unknown by the function because I don't want to maintain a lookup-list).
The function needed to pull the name of the first key, IE. channels[thiskey][notthisone] without knowing the name of that first key.
I couldn't solve it, been trying for hours, but Simon solved it for me, he's solved a bunch of stuff for me in the past too, ergo the beer
The function needed to pull the name of the first key, IE. channels[thiskey][notthisone] without knowing the name of that first key.
I couldn't solve it, been trying for hours, but Simon solved it for me, he's solved a bunch of stuff for me in the past too, ergo the beer
Marcus
Re: Limit put keys of array to first level?
If anyone's curious of what I'm doing with it, I'm building an IRC client entirely in LiveCode.
At this point (With Simons help above) I currently have: Connecting and authenticating with server, multi-channels, shorthands for join and part, userlist and channel list.
Next up will probably be a settings tab and more short commands.
At this point (With Simons help above) I currently have: Connecting and authenticating with server, multi-channels, shorthands for join and part, userlist and channel list.
Next up will probably be a settings tab and more short commands.
Marcus
-
- VIP Livecode Opensource Backer
- Posts: 7229
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Limit put keys of array to first level?
Glad you got it working. As far as I can see, "the keys" and Simon's method both return the same thing: the first level of the array. I probably missed something.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Limit put keys of array to first level?
Yeah, Jacque.
That is what I'm seeing as well. Not clear why "put the keys" is not working.
Simon
That is what I'm seeing as well. Not clear why "put the keys" is not working.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!