Script won't work once I create a standalone app

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
laurpapo
Posts: 38
Joined: Thu Jun 21, 2012 4:25 pm

Script won't work once I create a standalone app

Post by laurpapo » Tue Oct 08, 2013 2:54 pm

Hello,

I have a bit of code that I've used on multiple cards that resizes the text of all buttons on a card as the user resizes the stack. It works perfectly fine during development, and it continues to work for all but one card once I create the standalone app.

Basically, once the stack is resized, it calls a resize text handler, which fits the text of each button to the button's new size. Then, it looks for the smallest text size in the buttons and sets the rest of them to that size (so they all stay the same size each time). Somehow, once this is a standalone app, it doesn't work for the first card, but it still works just fine for the rest of them.

Code: Select all

   #RESIZE BUTTON TEXT
   
   repeat with x=1 to the number of buttons of current card
      
      --store the starting size of the text of the field
      put the textsize of button x of current card into tTextsize
      
      --check to see if the size of the text is too big
      if the formattedHeight of button x of current card > the height of button x of current card then
         --make the text size smaller
         repeat until formattedHeight of button x of current card <= the height of button x of current card
            subtract 1 from tTextsize
            
            --if the text size is not less than the minimum size of the text box
            if tTextsize >= the cMinimumTextSize of button x of current card then
               set the textsize of button x of current card to tTextsize
            else 
               exit repeat
            end if
         end repeat
         
         
         --if the text size is too small
      else if the formattedHeight of button x of current card < the height of button x of current card then
         repeat until the formattedheight of button x of current card >=the height of button x of current card
            add 1 to tTextSize
            
            --if the text size is not less than the minimum 
            if tTextsize<=the cMaximumTextSize of button x of current card then
               set the textsize of button x of current card to tTextsize
            else
               exit repeat
            end if
         end repeat
      end if
      
      --check to see if the width of the text is too big
      if the formattedWidth of button x of current card > the width of button x of current card then
         --make the text size smaller
         repeat until formattedwidth of button x of current card <= the width of button x of current card
            subtract 1 from tTextsize
            
            --if the text size is not less than the minimum size of the text box
            if tTextsize >= the cMinimumTextSize of button x of current card then
               set the textsize of button x of current card to tTextsize
            else 
               exit repeat
            end if
         end repeat
      end if
   end repeat
   
   
   global gSizes
   
   repeat with x=1 to the number of buttons of current card
         put the textsize of button x of current card &cr after gSizes
   end repeat
   sort gSizes
   repeat with x=1 to the number of buttons of current card
         set the textsize of button x of current card to line 1 of gSizes
   end repeat
Any ideas would be greatly appreciated!

Thanks!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Script won't work once I create a standalone app

Post by Simon » Tue Oct 08, 2013 6:11 pm

Hi laurpapo,
I haven't gone through your code as I assume it's working because cards past cd 1 do work. With that in mind it must be something to do with the start of your application. Many things happen at the start of an app e.g. loading of liveCode libraries, your own preOpen... scripts etc. and as such this may be where the problem lies. (In the IDE libraries load when you start the IDE so this may be why it works in the IDE and not the standalone).
As a test try moving your text resize to the bottom of a/the openCard script of your first card, see if that helps. You might want a lock/unlock screen in there as well.

A question is when do you run the resize? Is it "on resize"? or have you made a separate handler for it?
What happens when you return to card 1? Is the button text still the incorrect size?
Add a button for experimentation that just runs the resize script on card 1, let everything load in your standalone and then hit the button. Does that resize the text correctly?

hmmm... There is the question about do other object resize correctly on card 1? (maybe you only resize text).

Lots of fun debugging to be done :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

laurpapo
Posts: 38
Joined: Thu Jun 21, 2012 4:25 pm

Re: Script won't work once I create a standalone app

Post by laurpapo » Mon Oct 14, 2013 10:24 pm

Thanks for your help! I couldn't actually figure it out and ended up taking a shortcut--I didn't actually fix the problem but created a workaround.

Thanks!

Post Reply