Dice roller problem

I’m trying to make a dice roller for a game and I keep getting an error that I don’t understand.

here is the code:
on clicked theObject
set dicerolls to {}
set dicepool1 to the (content of combo box “attribute”) as number
set dicepool2 to the (content of combo box “ability”) as number
set dicepool to (dicepool1) + (dicepool2)
repeat (dicepool) times
set eachdice to (random number from 1 to 10)
set the end of dicerolls to eachdice & space
end repeat
display dialog ("Here are the dice rolls: " & dicerolls)
(Add your script here.)
end clicked

when I run this I get this error:

Can’t make «class conT» of «class comB» “attribute” of «script» into type number. (-1700)

Any help would be greatly appreciated

Thanks
Michael

As covered many times before, the reference to the objects will cause an error because you haven’t given a full reference to them. Hint: you need to list the entire hierarchy of views until you reach the window object (i.e., ‘content of combo box “attribute” of window “main”’ or ‘content of combo box “attribute” of tab view item 1 of tab view 1 of window “main”’, etc.).

Jon

there are several things wrong with this script as far as i can see:

  1. combo boxes don’t have clicked handlers. check interface builder for connections and appropriate handlers

  2. I think you want “contents of combo box” – in some cases ‘content’ and ‘contents’ are the same but not aways. in this case prollay no difference.

  3. if you’re going to refer to an object by name, in my experience you have to refer to the whole object path, as in:

contents of combo box “attribute” of window “main”

or else just:

on clicked theObject
if name of theObject is “attribute” then
set dicepool 1 to contents of theObject
end if
end clicked

Thank you for the help. I forgot to add the tell window “main” part to it.

I am still working on this roller after taking some time off from it and I can’t get this if statement to work

on clicked theObject
tell window “main”
set dicerolls to {}
set success to {}
set dicepool1 to the (content of combo box “attribute”) as number
set dicepool2 to the (content of combo box “ability”) as number
set dicepool to (dicepool1) + (dicepool2)
if (dicepool1 or dicepool2) is greater than “3” then
repeat (dicepool) times
set eachdice to (random number from 1 to 10)
if eachdice is greater than “6” then
set the end of success to (1 as number)
end if
if eachdice is greater than “9” then
set the end of success to (1 as number)
end if
set the end of dicerolls to eachdice & " "
end repeat
else
repeat (dicepool) times
set eachdice to (random number from 1 to 10)
if eachdice is greater than “6” then
set the end of success to (1 as number)
end if
end repeat
end if
set content of text field “Resultsfield” to dicerolls as string
set content of text field “successfield” to length of success & " successes" as string
end tell
end clicked

when I run this I get the error if I put 2 in for dicepool1:

Can’t make 2 into type boolean. (-1700)

Thanks for the help

This line:

if (dicepool1 or dicepool2) is greater than “3” then

Here dicepool1 and dicepool2 are evaluated as boolean. Change to:

if (dicepool1 > “3”) or (dicepool2 > “3”) then

If you wanted to compare numbers, then coerce the “3” to 3 as number, but you probably want integer.

“3” as integer

That worked. Thank You for your help