4 Replies Latest reply on Jan 26, 2011 3:08 PM by Jhon Carlo

Hi,

I have a list with many numbers, for example [234, 235, 236, 237 .....]. If I want access to  the first value of the list I can use for example the command: "put MyList [1]" and I get 234.
Now I need to have a script that increases the number in square brackets of "MyList" by one unit (MyList[2]; MyList [3] etc..) in order to obtain 235, 236 etc.. If I use the command "setAt" or  "MyList [1] = MyList [1] + 1",  with "put MyList" I get the value 2, 3 etc.. and not 235, 236 ... that I need.

What might be the way to the solution?
Thanks.

• ###### 1. Re: How to increase the number of access to a list

There is nothing wrong with the code "MyList [1] = MyList [1] + 1". It works as expected.

What you want though is "MyList = MyList + 1".

• ###### 2. Re: How to increase the number of access to a list

If I use "MyList = MyList + 1", if my list is equal to the following for example: [0, 11, 123, 234, 6443], the result will be: [1, 11, 123 234, 6443], but it is not what I want. I try to be more clear.
MyList = [224, 336, 445, 224, 779 etc ...]
Now, without changing the values of "MyList", I need to access the first, second, third .... etc value.
The first hypothesis might be:
MyList [1] (I obtain the value 224 and it is good)
MyList [2] (I obtain the value 336 and it is good)
MyList [3] (I obtain the value 445 and it is good)
etc. .........
but the list is very long and change, I would like a script, for example "on mouseUp me" to increase (not the value of the first list [224.336 etc]) but only the single value inside the brackets for example: MyList [4], MyList [5], MyList [6], MyList [7] ... [8] ... [9] and so on.
How can I do?
I apologize for my bad English.

• ###### 3. Re: How to increase the number of access to a list

Do you mean something like:

property pStartingIndex
property MyList

on beginSprite me
MyList = [224, 336, 445, 224, 779]
pStartingIndex = 1
end

on mouseDown me
repeat with Index = pStartingIndex to MyList.count
put MyList[Index]
end repeat

pStartingIndex = pStartingIndex + 1
if pStartingIndex > MyList.count  then pStartingIndex = 1

put "______________"  -- add breaks between mousedowns
end  mouseDown

• ###### 4. Re: How to increase the number of access to a list

Thanks Production Monkey

I tried to do a first test and it works.
Thanks a lot!!!