can't set property "script" [solved]

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

can't set property "script" [solved]

Post by SteveTX » Tue Jul 09, 2013 12:07 am

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
Last edited by SteveTX on Tue Jul 09, 2013 7:42 am, edited 1 time in total.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: can't set property "script"

Post by mwieder » Tue Jul 09, 2013 12:28 am

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.

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: can't set property "script"

Post by SteveTX » Tue Jul 09, 2013 12:42 am

assignMenuButton buttonPos: 1 behindImage: button_back.png buttonBehavior: showMain

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: can't set property "script"

Post by SteveTX » Tue Jul 09, 2013 2:53 am

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.

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: can't set property "script"

Post by SteveTX » Tue Jul 09, 2013 3:17 am

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?

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: can't set property "script"

Post by mwieder » Tue Jul 09, 2013 5:28 am

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

SteveTX
Posts: 170
Joined: Sun Jan 17, 2010 9:00 pm

Re: can't set property "script"

Post by SteveTX » Tue Jul 09, 2013 7:42 am

Worked. Thanks!

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

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

Post by mwieder » Tue Jul 09, 2013 6:59 pm

Yay! :-P

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

Post Reply