2 dimensional lists problem

I have a problem when using a list. I run a handler togehter with a 2 dimensional list which is part of another script. The code in the handler works then through the elements of the list.

The code looks something like this:

put (("NameOfSomeImage1", "WhatTextToEnter1"), ("NameOfSomeImage2", "WhatTextToEnter2")) into global PointToClick_ValueWhatToEnter_List 
run _Library_Script.NameOfSomeImage_WhatTextToEnter

I can now use the same handler with a different amount of 2dimensional items of that list. I can extend it to 3 dimensional items or to 4.

But if I reduce it to only one 2dimensional item, like:

put (("NameOfSomeImage1", "WhatTextToEnter1")) into global PointToClick_ValueWhatToEnter_List 

the handler code fails. The list only seems to contain the 1 item of the 2dimensional list. The second returns to be empty. Why is that?

The handler code looks like:


	repeat with each item of global PointToClick_ValueWhatToEnter_List
		if it is not empty then put it into 2dimensionalitem
		put item 1 of 2dimensionalitem into part1
		put item 2 of 2dimensionalitem into part2
		click on part1
		typetext part2
	end repeat 

If I change the code to:

put (("NameOfSomeImage1", "WhatTextToEnter1","","")) into global PointToClick_ValueWhatToEnter_List 

The first repeat run is ok, part1 and part2 are properly used, but the repeat fails because for the subsequent empty values the handler code fails with an error and the script stops, which it should not. because the script handler call is part of a longer list of calls and there are many more which follow :wink:

I hope someone has an idea whats going on…

P.S. I use Eggplant Starter Edition…

Try getting rid of your check for empty. That might be what’s messing it up, or if you really need to check for empty try using this:

if it is empty then next repeat

Hope this helps.

Allen

I tried your suggestion but is does not “cure” my code.

I moved out the essential part of my code into a playground, and it worked there:

Handler call:

put (("11", "12")) into global PointToClick_ValueWhatToEnter_List
run x_playground_library.testHandlerWithParameterList

Handler code:

to testHandlerWithParameterList
	repeat with each item of global PointToClick_ValueWhatToEnter_List 
		if it is not empty then put it into itemslist 
		
		put item 1 of itemslist into part1 
		put item 2 of itemslist into part2 
		
		put part1 
		put part2 
	end repeat 
end testHandlerWithParameterList


Log Result:

Tue, 3/3/09 8:11:42 PM	START		Running x_playground.script
11

12

Tue, 3/3/09 8:11:43 PM	SUCCESS		Execution Time 0:00:00 x_playground.script

Its obscure that the code does not work, when it need to use clicks and typetext instead of the put’s i used in the above playground code…

sigh

What’s happening when you only have one list is that Eggplant is iterating over your inner list–the parenthesis are just extra at this point.

I looked at it a bit more and I think you will actually want to use a property list in this case:

put ((imageToClick:"NameOfSomeImage1", textToType:"WhatTextToEnter1")) into global PointToClick_ValueWhatToEnter_List 

testHandlerWithParameterList

to testHandlerWithParameterList 
	repeat with each item of global PointToClick_ValueWhatToEnter_List 
		if it is not empty then put it into itemslist 
		click itemsList.imageToClick
		typeText itemsList.textToType
	end repeat 
end testHandlerWithParameterList 

Property lists are lists with a key/value pair and can be accessed with the “.” operator or the “'s” operator. Chapter 8 in the SenseTalk reference will come in handy. Setting these up as a property list will guarantee that each list will be handled as a single unit.

Hope this helps.

Allen

EDIT: I just thought of something else, you will want to turn around your check for empty, because if it is empty, the click and the typeText will still get executed and generate an error.

Ah, ok, understood.

Using a property list as you suggested cured my code.

I choosed that kind of notation over the one which comes with a propery list because the calls notation was much shorter, but that way my calls will become more descriptive and I am fine with it.

Thanks, I appreciate your help 8)

Using property lists here instead of lists is certainly a fine idea which may make your code clearer. Your original approach was fine, too. So I just wanted to explain why it wasn’t working.

As you know, you can create a list of lists very simply like this:

put ((11,12), (13,14)) into listOfLists

What’s less obvious is that this code will NOT make a list of lists (a two-dimensional list):

put ((11,12)) into simpleList

The reason is that the outer parentheses in this case are simply a grouping operator, not a list-creation operator. If you look very carefully at the color of the parentheses in the script editor you’ll see that they are different colors in this case.

It’s easy to force this to be a nested list within a list – just add a comma:

put ((11,12),) into listOfLists

The extra comma tells SenseTalk that this is a list but doesn’t add any extra items.

P.S. Your playground example has the same problem, but it wasn’t obvious because of the way you displayed the output. Change your put statements to label the values being displayed and I think it will be clear:

    put "part1 is " & part1
    put "part2 is " & part2

I hope this explanation helps. :slight_smile:

:shock: Ah. OK. Now I get it.

Thanks for the clarification. 8)

One handy think to do is to use the debugger when you’re running this and test whether you have a list or not:

put (1,2) into myList
put myList is a list
true

I often catch errors via the debugger this way.
Oh, the paradox of a Typeless Language.