Default Script

Moderators: LCMark, LCfraser

Post Reply
pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Default Script

Post by pink » Mon Aug 13, 2018 6:12 pm

How do I add a default script to a widget?

I tried manually adding a "Support" folder and a defaultscript.livecodescript file, but it did not get included.
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 168
Joined: Thu Apr 18, 2013 2:48 pm

Re: Default Script

Post by livecodeali » Mon Aug 13, 2018 10:25 pm

support should be lowercase, although possibly that isn't the issue if you're on an os with a case insensitive file system.

Your default script stack needs to be named "your.widget.identifier.__DefaultScript", eg:

Code: Select all

script "com.livecode.widget.navbar.__DefaultScript"
Other than that, the only reason I can think that it wouldn't work is a script parsing error in the default script...

Actually, what do you mean by 'didn't get included'?

pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Re: Default Script

Post by pink » Mon Aug 13, 2018 11:46 pm

by didn't get included, I meant that it didn't show up when I tested the widget and opened the script


the script is named:

Code: Select all

script "community.livecode.madpink.buttonbar.__DefaultScript"
and the widget is named:

Code: Select all

widget community.livecode.madpink.buttonbar
do I need to include anything in the widget to look for the script's existence?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 168
Joined: Thu Apr 18, 2013 2:48 pm

Re: Default Script

Post by livecodeali » Tue Aug 14, 2018 8:52 am

No, it should happen automatically. However, I'm wondering if there may be a docs issue here - we changed default scripts so that the handlers specified show up in the left hand side, rather than the script actually being automatically filled in - does your default script consist of (a) handler(s) and is its name not showing up in the default handler list?

pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Re: Default Script

Post by pink » Tue Aug 14, 2018 3:38 pm

Thus far I do have 1 handler and it is showing up on the handler list.
Also, changing the folder name to "support" did not help

Here is my widget so far if looking at helps:
https://github.com/madpink/buttonbar-livecode-builder
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3246
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Default Script

Post by bn » Tue Aug 14, 2018 7:57 pm

Greg,

your default script has some typos

this compiles

Code: Select all

on mouseUp

end mouseUp

--Sent if mType is "Action", need to add more cases as needed
on actionSelected
  switch the buttonSelected of me
   case 1
      --Put Actions here
      break
   case 2
     --Put Actions here
     break
  end switch
end actionSelected

function getSelected pDelim pType
   local tData, tSelected

   if pDelim is empty then put ";" into pDelim
   if pType is empty then put "label" into pType

   put the buttonData of me into tData
   repeat for each key tKey in tData
      if tData[tKey]["clicked"] then
         if tSelected is not empty then
            put pDelim after tSelected
         end if
         put tData[tKey][pType] after tSelected
      end if
   end repeat
   return tSelected
end getSelected
Kind regards
Bernd

pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Re: Default Script

Post by pink » Fri Aug 17, 2018 1:51 pm

I did correct the script, but I still cannot get the default script to work

In fact, I grabbed the tree view widget off github and tried put it into the extension builder, and the default script doesn't show up there either... or is it possible that it doesn't work in "testing" mode?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1785
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Default Script

Post by [-hh] » Fri Aug 17, 2018 3:25 pm

Setting a default script never worked correctly for me.
It is much easier to set a widget script in your widget in "OnOpen".

Code: Select all

public handler OnOpen()
    ...
    post "if the script of me is empty then set script of me to " & myScript()
end handler

handler myScript () returns String
--> use \q for quote, \n for newline
end myScript
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3246
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Default Script

Post by bn » Fri Aug 17, 2018 3:32 pm

the default script did not work for me either.
I resorted to make a button that sets the script.

but Hermann's solution might be easier.

Kind regards
Bernd

pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Re: Default Script

Post by pink » Fri Aug 17, 2018 4:11 pm

I think I like Hermann's approach better than using the default script as a separate file

Thanks both of you
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 168
Joined: Thu Apr 18, 2013 2:48 pm

Re: Default Script

Post by livecodeali » Wed Aug 22, 2018 3:44 pm

I'm still confused as to the specific issue here - if the handler shows up in the default handler list (and nothing else) then that is the expected behavior - we did away with default scripts actually populating the script, they merely define a list of handlers for the default handler list.

If I load the tree view with a new identifier I get the same as a tree view in the IDE, namely the four handlers in the left hand side as default handlers.

Although Hermann's method works, it might not always be possible to do such a thing and has different behavior from the other controls, plus you have to write your script with escaped characters - none of which strike me as easier - better to identify the bug if there is one and fix it (it's likely not a difficult fix). On the other hand, the current situation is not idea for what you want to do as I see your default handler is actually split into multiple handler definitions.

pink
Posts: 224
Joined: Wed Mar 12, 2014 6:18 pm

Re: Default Script

Post by pink » Wed Aug 22, 2018 6:24 pm

the confusion for me really started because I was remembering the default script that used to get populated for certain widgets, and all of the built-in widgets still have the defaultscript.livecodescript file with them. Didn't realize at that time that they were no longer being populated on purpose (really, just assumed I did something)

anyhow, I liked having the basic outline of a script
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Post Reply

Return to “LiveCode Builder”