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)
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.).
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: