Errors in AS Studio App

Hi again,

I need some assistance with what should be a very simple AS Studio app. I have made many Studio apps and had good success.

This app has one window, that contains 2 Table Views. I want to select one item from the left table view (Votees) and one or more items from the right table view (Voters) so that one or more Voters can vote for one Votee.

I dragged two Table Views into the main window, set each to have only one column, named them “Voters” and “Votees”, set both to have the main script control them, and wrote this code:


on awake from nib
	beep 2
	set votersTable to table view 1 of scroll view 1 of window 1
	set voteesTable to table view 1 of scroll view 2 of window 1
	(*set votersDataSource to data source of table view "Voters" of window 1
	tell votersDataSource to make new data column at end of data columns with properties {name:"Voters"}
	set voteesDataSource to data source of table view "Votees" of window 1
	tell voteesDataSource to make new data column at end of data columns with properties {name:"Votees"}*)
end awake from nib



on clicked theObject
	tell window 1
		if name of theObject is "Voters" then
			my addVoter(selected rows of theObject)
		else if name of theObject is "Votees" then
			my setVotee(selected rows of theObject)
		else if name of theObject is "Vote" then
			my castVote()
		else if name of theObject is "Reset" then
			my resetGame()
			beep
		end if
	end tell
end clicked



to addVoter(voterRow)
	beep
	set contents of text field "debug" of window 1 to "addVoter"
end addVoter

to setVotee(voteeRow)
	beep
	set contents of text field "debug" of window 1 to "setVotee"
end setVotee

to castVote()
	beep
	set contents of text field "debug" of window 1 to "castVote"
end castVote

to resetGame()
	beep
	set contents of text field "debug" of window 1 to "resetGame"
end resetGame

There are also two buttons on the layout.

When run, I get a runtime error “-1708”, but when this is dismissed, then clicking on any of the four items (the two tables and the two buttons) properly gives a beep.

Each of the tables only needs one column, so they are really lists. All I need is to get the selected items when the “Vote” button is pressed.

I am using data source because it is recommended by the documentation.

Questions:

  1. Can anyone see why I am getting the -1708 code? I remember getting this years ago, and don’t remember what fixed it.

  2. Is there an IB object for just a one-column list? Or is the only way to set a Table View to one column?

  3. Does anyone see anything wrong with the two assignment statements for the Table Views? When I comment out everything except these two lines, I STILL get the -1708 error.

Which object is awaking from nib? Perhaps it would be more appropriate to use an on launched handler.

Thanks for the reply.

I got rid of the -1708 error - apparently “set foo to make new data source…” shouldn’t be targeted at the window.

The on awake from nib is executing, because the “beep 2” executes.

So now with my new code, when I query my running application from Script Debugger (isn’t there a way to debug AS Studio code with Xcode?), it shows the data source getting populated correctly but the data does not show up in the Table Views.

Here is the new code:


property theDataSource : null
property playerList : {"BlondeAmazon", "Scotty4168", "MD_2_Be", "muzscman", "sansri88", "CatSnak", "Dezbend"}
on awake from nib
	
	beep 2
	set theDataSource to make new data source at end of data sources with properties {name:"Players"}
	tell theDataSource to make new data column at end of data columns with properties {name:"playerNames"}
	repeat with theRow from 1 to 7
		tell theDataSource
			set r to make new data row at end of data rows of it
			set contents of data cell "playerNames" of r to item theRow of playerList
		end tell
	end repeat
	
	set theDataSource to data source of table view "Voters" of scroll view "Voters" of window "mainWindow"
	set theDataSource to data source of table view "Votees" of scroll view "Votees" of window "mainWindow"
	tell table view "Voters" of scroll view "Voters" of window "mainWindow" to update
	tell table view "Voters" of scroll view "Voters" of window "mainWindow" to update
	
end awake from nib

I know I am almost there.

  1. There is no “Data Source” object in Interface Builder that I can find. This is in Xcode 3. The examples using Xcode 2 mention dragging one in and connecting it to the tables, but the new documentation advises against this. I’m confused.

  2. I did not set any connections in IB between the table views and the data source, as there is no data source object to add to the list of instances.

Somehow all I need now is for the Table Views to display my 7 rows and I will be on my way.

The syntax of data source and the table view is confusing to me - it seems as if it should be "set data source of Table View “foo” to {some data source}, but it’s the opposite.

EDIT:

I solved it. I had the assignment backwards.

It should be

set data source of table view “Voters” of scroll view “Voters” of window “mainWindow” to theDataSource

And now it fills both columns.

Also the loop I had to load the 7 rows can be replaced by

append theDataSource with playerList

Thanks for taking a look.

Now I am stuck on a row that won’t delete.

The data source “theDataSource” is assigned as the data source to two table views.

Here’s the definition of the data source and its columns and rows and connections to the table views:


on awake from nib
	set contents of text view "thePostText" of scroll view "results" of window "mainWindow" to ""
	set theDataSource to make new data source at end of data sources with properties {name:"Players"}
	tell theDataSource
		make new data column at end of data columns with properties {name:"playerNames"}
		make new data column at end of data columns with properties {name:"votersFor"}
		make new data column at end of data columns with properties {name:"currentVotedPlayer"}
	end tell
	append theDataSource with playerList
	set data source of table view "Voters" of scroll view "Voters" of window "mainWindow" to theDataSource
	set data source of table view "Votees" of scroll view "Votees" of window "mainWindow" to theDataSource
	
end awake from nib

Here is the handler that I call when a player accrues a majority of votes. I need to delete that player’s row from the data source.


to lynch(rowOfThePlayerToLynch)
	log rowOfThePlayerToLynch --->>> data row id 22 of data source id 12 
	display dialog "In Lynch" -->>displays "In Lynch"
	tell theDataSource
		set theLynchee to contents of data cell "Playernames" of rowOfThePlayerToLynch
		log theLynchee --->>> "CatSnak" (correct)
		delete rowOfThePlayerToLynch --->>>ERROR "Can't get item 6 of every data row of data source id 12. (-1728)"
	end tell
	set (contents of text view "thePostText" of scroll view "results" of window "mainWindow") to theLynchee & " has been lynched." -->>>Works correctly.
end lynch

Somehow the “delete” statement isn’t working, and as far as I can tell it takes a row object which is logged as a row object and I am stumped as to why I get this error.

Can anyone see what I am doing wrong in this delete row code? (NOTE: I have tried “delete data row rowOfThePlayerToLynch” and “delete item 1 of data row rowOfThePlayerToLynch” with different errors but still no success)