Here's how to add an item to the end of a list

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
MichaelBluejay
Posts: 112
Joined: Thu Jul 01, 2010 11:50 am

Here's how to add an item to the end of a list

Post by MichaelBluejay » Wed Oct 09, 2019 1:31 pm

I'm replacing my original post with this one, because the way I thought I came up with for easily adding an item to the end of a list without manually inserting commas, well, I can't get it to work now. I'd delete this thread except I don't have that ability.

So, to add to the end of a list, there's no better way than put newItem & comma after "tList".
Last edited by MichaelBluejay on Wed Oct 09, 2019 4:01 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6160
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Here's how to add an item to the end of a list

Post by dunbarx » Wed Oct 09, 2019 2:53 pm

Michael.

Your snippet will not compile, you need to:

Code: Select all

put "figs" into item (num(items of tList )+1) of tList
Now then:

Code: Select all

on mouseUp
   put "apples,berries,cherries" into tList
   put "figs" into item last+1 of tList
end mouseUp
yields ""figs,berries,cherries", LC is ignoring the "last+" portion, as it often does with spurious words. This "feature" of LC can throw you. It does me. I wish the parser was more strict.

Keep having fun playing around. Discovering that LC will create the correct number of chunks when asked is cool, eh?. Try this;

Code: Select all

 put "apples,berries,cherries" into tList
   put "figs" into item 10 of tList
Write back any time with all you discover, as well as complaints. :wink:

Craig

MichaelBluejay
Posts: 112
Joined: Thu Jul 01, 2010 11:50 am

Re: Here's how to add an item to the end of a list

Post by MichaelBluejay » Wed Oct 09, 2019 3:53 pm

Well, I was sure it worked for me, but now I can't get it to. I'm wondering if there's maybe some small syntax thing I'm missing.

Guess I'm back to manually inserting commas.

I'd delete this thread except there's no way to do that as a basic user.

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2120
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Here's how to add an item to the end of a list

Post by [-hh] » Wed Oct 09, 2019 6:36 pm

You write "newItem & comma". Write "comma & newItem".

A bit more compact:

Code: Select all

put "",newItem after theList -- use value of variable newItem
put ",abcd" after theList -- use value
shiftLock happens

MichaelBluejay
Posts: 112
Joined: Thu Jul 01, 2010 11:50 am

Re: Here's how to add an item to the end of a list

Post by MichaelBluejay » Wed Oct 09, 2019 9:32 pm

Thank you. I do like "",newitem more than comma & newItem. It's easier to tell at a glance that we're appending an item to the list.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”