Default Script

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
pink
Posts: 272
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: 192
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: 272
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: 192
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: 272
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: 3975
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: 272
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: 2262
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: 3975
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: 272
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: 192
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: 272
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

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Default Script

Post by PaulDaMacMan » Fri Sep 11, 2020 4:41 pm

[-hh] wrote:
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
Just wanted to add a note here that HH's method to set a Widget's LCS script doesn't appear to work anymore (LC 9.6.1 Mac), it throws the error "LCB Error script access not allowed". Maybe this was changed for security reasons?

Anyway the defaultscripts do work but they seem a bit tricky to get right. Ensure that your in-line lcdoc mark-up is working correctly or the default script won't show up.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

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

Re: Default Script

Post by mwieder » Mon Sep 14, 2020 2:59 am

I'm finding that the default script doesn't show up in the Extension Builder window ("No default script found") but if you click the Edit button the script does appear in the script editor and also populates the default script pane in the Extension Builder.

LC 9.6.1.

PaulDaMacMan
Posts: 616
Joined: Wed Apr 24, 2013 4:53 pm
Contact:

Re: Default Script

Post by PaulDaMacMan » Fri Sep 25, 2020 3:22 pm

mwieder wrote:
Mon Sep 14, 2020 2:59 am
I'm finding that the default script doesn't show up in the Extension Builder window ("No default script found") but if you click the Edit button the script does appear in the script editor and also populates the default script pane in the Extension Builder.

LC 9.6.1.
Yeah, the Extension Builder definitely needs some work:
- I find the same problem with default script not showing in the window until clicking the edit script.
- My SVG icons do not replace or align with the default icon in the Builder window.
- I have to manually delete files in my project folder, clear the Documentation cache folder for my project in the RunRev folder, and quit/relaunch in order for documentation updates to show up in the dictionary.
- I sometimes have to manually delete build files in my project folder and quit/relaunch or the compile log shows "module already loaded" and then won't recompile.
My GitHub Repos: https://github.com/PaulMcClernan/
Related YouTube Videos: PlayList

Post Reply

Return to “LiveCode Builder”