Page 1 of 1

Handler functioning in LiveCode 4.5.1 but not in LiveCode 7.

Posted: Tue Dec 22, 2015 1:59 am
by kresten
Hi
I have spent 2 weeks in experimenting to revitalize a long handler (to select and create pictogram buttons from each of 14 textfields, offering their choices of pictograms&text). The handler has been functioning faithfully at least since 2009, in earlier versions of my application and earlier versions of livecode at least until livecode 4.5.1. But now and here, in developpping a new version of my application in Livecode 7.1.0 it went on an all-out strike.(I have controlled that the textfields to pick from are locked now as they were previously) -
I hesitate to burden your fine forum with the long script of the handler, but it seems a rational way to avoid wasting the time of potential helpers

Code: Select all

--making and managing glyph buttons start--------------------------------------------------------------------------------------------------
on buttonmake
  global btfont
  put word 2 of the clickLine into theLine
  put the clickChunk into chunkInfo
  if chunkInfo = empty then exit to top
  --ask "Click Chunk" with chunkInfo
  set the itemdelimiter to tab
  put number of items in line theLine of target into itemCount
  repeat with n = 1 to itemCount
    put number of chars in item n of line theLine of target into line n of infoHold
    --ask "number of chars in item" && n with line n of infoHold
  end repeat
  if theLine = 1 then put 1 into charStart
  else put number of chars in line 1 to (theLine - 1) of target + 2 into charStart
  put charStart into charStart2
  repeat with n = 1 to itemCount
    add line n of InfoHold to charStart2
    put charStart2 into line n of ItemStart
    --ask "Line Info" with line n of InfoHold
    --ask "Itemstart" with line n of itemStart
  end repeat
  put charStart into ItemStart2
  delete last line of ItemStart
  put ItemStart into line 2 of ItemStart2
  put 0 into x
  put ItemStart2 into startRange
  repeat with n = 1 to number of lines in startRange
    add x to line n of startRange
    add 1 to x
  end repeat
  put startRange into endRange
  repeat with n = 1 to number of lines in endRange
    add line n of infoHold to line n of endRange
  end repeat
  repeat with n = 1 to number of lines in endRange
    put empty into startTest
    if word 2 of chunkInfo >= line n of startRange then put "True" into startTest
    put empty into endTest
    if word 4 of chunkInfo <= line n of endRange -1 then put "True" into endTest
    --ask "start Range" && word 2 of chunkInfo with line n of startRange
    --ask "startTest" && n with startTest
    --ask "endTest" && n with endTest
    if startTest = "True" and endTest = "True" then
      put n into itemNumber
      --      ask "Line" && theLine && "Item Number" && itemNumber with
      put item itemNumber of line theLine of target into lomme
      if the result = "cancel" or it = empty then exit to top
      --      put it into item itemNumber of line theLine of target
      exit repeat
    end if
  end repeat
  --  if the optionkey is down and the controlkey is up then
  --    descriptiontext
  --  end if
  --  if the optionkey is down and the controlkey is down and movetext is empty then
  --    chooseline
  --  end if
  --  if the optionkey is down and the controlkey is down and movetext is not empty then
  --    placeline
  --  end if
  put lomme into picktext
  put char 1 of picktext into btname
  put empty into char 1 to 2 of picktext
  if picktext is empty then
    put "No description" into htext
  else
    put picktext into htext
  end if
  -- main window
  if the phenowindow of me is mainwindow then
    put "27,64,59,96" into knaprect
  end if
  create button in group ID 3655
  set name of it to btname
  set textfont of it to btfont
  set textsize of it to 24
  set textstyle of it to plain
  set style of it to transparent
  set the foregroundcolor of it to "black"
  set rect of it to knaprect
  put "on mouseup" into line 1 of scriptbox
  put "if the optionkey is up and the keysdown is not in" && quote & 99,100,115 & quote && "then" into line 2 of scriptbox
  put "ikonmsg" into line 3 of scriptbox
  put "end if" into line 4 of scriptbox
  put "end mouseup" into line 5 of scriptbox
  put "on mousewithin" into line 6 of scriptbox
  put "if the optionkey is down then" into line 7 of scriptbox
  put "set the tooltip of me to" && quote & htext & quote into line 8 of scriptbox
  put "end if" into line 9 of scriptbox
  put "end mousewithin" into line 10 of scriptbox
  put "on mousestilldown" into line 11 of scriptbox
  put "if the optionkey is down then" into line 12 of scriptbox
  put "set cursor to arrow" into line 13 of scriptbox
  put "set loc of me to the mouseloc" into line 14 of scriptbox
  put "end if" into line 15 of scriptbox
  put "select empty" into line 16 of scriptbox
  put "btnmsg" into line 17 of scriptbox
  put "end mousestilldown" into line 18 of scriptbox
  put "on doomed" into line 19 of scriptbox
  put "send" && quote & deleteme & quote && "to me in 10 milliseconds" into line 20 of scriptbox
  put "end doomed" into line 21 of scriptbox
  set script of it to scriptbox
end buttonmake   

--making and managing glyph buttons end-------------------------------------------------------------------------------------------------------
If I could open my new stack version in Livecode 4.5.1 I would have tried to go on from there, bur 4.5.1 doesn't recognize it as a stack. :cry:
Hoping for advice
Best regards
Kresten

Re: Handler functioning in LiveCode 4.5.1 but not in LiveCod

Posted: Tue Dec 22, 2015 2:21 am
by FourthWorld
The IDE's File -> Save As menu item brings up a dialog to save a stack file, and at the bottom includes a popup list of file versions, supporting all previous file formats going back more than a decade.

As for the code issue, I've only skimmed it so far and don't have a recommendation on the issue at hand, but I see you're writing scripts within your script to insert into newly-created buttons - have you consider using a behavior script for that?

Re: Handler functioning in LiveCode 4.5.1 but not in LiveCod

Posted: Tue Dec 22, 2015 4:38 am
by quailcreek
Hi Kresten,
I had a brief look at your code too. I'd like to make a suggestion. Instead of building the script that goes into the new buttons, line by line, I would do this. Something similar to Richards idea.

Have a hidden and disabled button on the cd with the compete script you want to have in the new buttons. Let's say you name it "Fred". Then in your buttonMake script, instead of building the script you simply have:

Code: Select all

set the script of it to the script of btn "Fred"
Also, unless you need unicode text, I would try running your stack in LC .6.7.8
I have stacks that I wrote in 2007 and they are still running today...

Re: Handler functioning in LiveCode 4.5.1 but not in LiveCod

Posted: Tue Dec 22, 2015 5:47 pm
by jacque
I'm with Richard, this is a good candidate for a behavior.

Re: Handler functioning in LiveCode 4.5.1 but not in LiveCod

Posted: Wed Dec 23, 2015 1:26 am
by kresten
Hi
Thank you for advices.
I installed the 6.7.8 LiveCode, and I saved v.2.7 compatible version and 5.6 compatible versions of the critical LC 7 version of my app.
I then tried to open the "v2.7 compatible" version with an old Livecode 4.5.1 : reply: "File is not a stack"
I then tried to open the "v 5.6 compatible " version with the new Livecode 6.7.8: reply: "Stack was produced by a newer version"-
So what is the idea in having those save as options ?
So: Was tut der kluge Hausvater ?
P.S. I understand the advice concerning script within script, but as I am sure, this is not what castrates the handler in LC 7, I will leave it.