CoopDaddio
CoopDaddio

Reputation: 627

How to create an array/list?

I would like to put multiple food items into a metaphoric "basket" in LiveCode. I know in Python this is done like this:

basket = ["orange", "apple", "tomato", "grapes"]

How would this be done in LiveCode? Additionally, I would also like LiveCode to separate all of the letters of each item in the basket. For example, "o", "r", "a", "n", "g", "e"... How do I do this?

Upvotes: 1

Views: 480

Answers (1)

Scott Rossi
Scott Rossi

Reputation: 885

You don't need an array for what you're asking. You can use a variable, like this:

put "orange,apple,tomato,grapes" into theBasket

To retrieve the contents of theBasket variable, you reference its items:

answer the items of theBasket -- answers the fruit names

To retrieve one item of theBasket variable:

answer item 3 of theBasket -- answers "tomato"

To get the number of fruits in the variable:

answer the number of items of theBasket -- answers 4

You don't explain what you want to do with letters of each fruit word, but you refer to the letters of a word as chars (characters):

put item 1 of theBasket into theFruit -- puts "orange" into a new variable
answer char 3 of theFruit -- answers "a"

To learn about actual LiveCode arrays, there's some great information here: http://revolution.byu.edu/arrays/introToArrays.php

Upvotes: 3

Related Questions