Page 1 of 1

can't set property "script" [solved]

Posted: Tue Jul 09, 2013 12:07 am
by SteveTX
I am dynamically reassigning button scripts as part of a menu system. The following command works once on buttons but doesn't seem to subsequently work. The script is less than 10 lines, is there also an unmentioned limit on how many times you can reassign a button's script?
Type Chunk: can't set property
Object application
Line set the script of button theButton to theScript
Hint on mouseUp

Code: Select all

command assignMenuButton buttonPos, behindImage, buttonBehavior
   put ("buttonMenu" & buttonPos) into theButton
   put "on mouseUp" & cr & \
             "   " & buttonBehavior & " " & buttonPos & cr& \
         "end mouseUp" into theScript
   set the script of button theButton to theScript
   put behindImage into buttonsCurrent[buttonPos,"image"]
   put "true" into buttonsCurrent[buttonPos]
end assignMenuButton

Re: can't set property "script"

Posted: Tue Jul 09, 2013 12:28 am
by mwieder
Nothing wrong with your script.
And I tried it several times here and it worked properly each time.
Put it in a repeat loop and it never failed.

Something else is going on.

Update: although it might depend on what you pass in as the buttonBehavior and buttonPos parameters.

Re: can't set property "script"

Posted: Tue Jul 09, 2013 12:42 am
by SteveTX
assignMenuButton buttonPos: 1 behindImage: button_back.png buttonBehavior: showMain

Re: can't set property "script"

Posted: Tue Jul 09, 2013 2:53 am
by SteveTX
Discovered the issue, I think. The error is dependent upon executing the script assigned to the button. Message path was mouseUP on button "MenuButton1" calling a command that called a command that would modify the script of button "MenuButton1", thus making it a self-modifying handler that violates the "script" command.

Re: can't set property "script"

Posted: Tue Jul 09, 2013 3:17 am
by SteveTX
wrote script into a command that would delete and recreate the button but ran into a similar issue but in a different form:
Type Chunk: can't delete object
Object application
Line if there is a button buttonName then delete button buttonName
Hint animateMenuClose
Is there a way to escape the message path so subsequent commands aren't self-referential?

Re: can't set property "script"

Posted: Tue Jul 09, 2013 5:28 am
by mwieder
There is.

put the modifying script into a separate handler, then call that handler after some time has passed. That way the mouseUp handler has a chance to finish up and get out of the message path.

Code: Select all

-- in mouseButton1 script
on mouseUp
  -- local buttonNumber
  --do things here
  put 1 into buttonNumber
  send "deleteAndRecreateMe buttonNumber" to this stack in 10 milliseconds
end mouseUp

-- in stack script
on deleteAndRecreateMe pNum
  -- if there is a button "MenuButton" & pNum then
  -- you know what to do here
end deleteAndRecreateMe

Re: can't set property "script"

Posted: Tue Jul 09, 2013 7:42 am
by SteveTX
Worked. Thanks!

Re: can't set property "script" [solved]

Posted: Tue Jul 09, 2013 6:59 pm
by mwieder
Yay! :-P

Your message contains 8 characters. The minimum number of characters you need to enter is 10.