Find a string in a stack card object script code

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Find a string in a stack card object script code

Post by mrcoollion » Tue Jul 03, 2018 6:19 am

How can i find a string in the code of a open stack.
I want to find all instances of a specific command in a stack.
E.g. Every Stack, Card en Object preferable with linenumber I used the command 'answer' in.

Regards,

Paul

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Find a string in a stack card object script code

Post by jmburnod » Tue Jul 03, 2018 8:26 am

Hi Paul,
Did you use Find/replace tools ?
Best regards
Jean-Marc
https://alternatic.ch

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Find a string in a stack card object script code

Post by richmond62 » Tue Jul 03, 2018 9:36 am

FR.png
F&R.png

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find a string in a stack card object script code

Post by mrcoollion » Tue Jul 03, 2018 10:22 am

I need to do this via code (scripting). It is part of an application (stack) i am developing.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Find a string in a stack card object script code

Post by jmburnod » Tue Jul 03, 2018 11:32 am

I need to do this via code (scripting)
In this case you may use a loop for each stack, cds and controls.
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Find a string in a stack card object script code

Post by dunbarx » Tue Jul 03, 2018 1:25 pm

Hi.

The script of any control, card or stack is a property of that object. So as Jean-Marc indicated, you can (Pseudo):

Code: Select all

repeat for each stack tStack in listOfStacks
  repeat for each cd tCd in stack tStack
    repeat foe each control tControl in cd tCard in stack tStack
  
      get the script of control tControl
      if yourString is in it then processAway  --or you might use one of the offsets or a find
      ...
  
Craig Newman

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9250
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Find a string in a stack card object script code

Post by richmond62 » Tue Jul 03, 2018 1:41 pm

Well, I'd get a list of all the controls to start with:

Code: Select all

on mouseUp
   put the number of controls into KONT
   put 1 into X
   repeat until X> KONT
      put the name of control X into line X of fld "oList"
      add 1 to X
   end repeat
end mouseUp

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find a string in a stack card object script code

Post by mrcoollion » Tue Jul 03, 2018 1:59 pm

Great :D :D :D
The part 'get the script of control tControl' is what I was looking for.

Really a lot of thanks to you all for helping me out here :!: :!: :!:

:D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find a string in a stack card object script code

Post by mrcoollion » Tue Jul 03, 2018 5:22 pm

Another question (maybe worth a new thread)

When I call a function from object x in card y of stack z but this function is situated in the main stack or even another sub-stack, Is there a way to find out where the function has been used or called from (without putting this in the functions parameters)?

When I put the following statements in the function situated in the main stack:
'This seems to work 'put the short name of current stack into tCurrentStack'
This seems to work 'put the short name of current card into tCurrentCard'
This does NOT work 'put the short name of current control into tCurrentControl' :(

Regards,

Paul

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find a string in a stack card object script code

Post by mrcoollion » Tue Jul 03, 2018 5:50 pm

I cracked the code :idea: :lol:

This works:

Code: Select all

   put the short name of current stack into tCurrentStack
   put the short name of current card into tCurrentCard
   put the short name of the target into tCurrentControl

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9567
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Find a string in a stack card object script code

Post by dunbarx » Wed Jul 04, 2018 12:59 am

Hi.
The part 'get the script of control tControl' is what I was looking for.
This goes way back to HC days.

It is not commonly known, or appreciated, that the script of an object is a property, and not a container.

You cannot "put" a new line into a script, or modify it directly. You have to extract it into a variable, change it within that variable, and then (re)set the property in its entirely.

Why this is so is still a mystery.

Craig

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Find a string in a stack card object script code

Post by mrcoollion » Wed Jul 04, 2018 7:11 am

Thanks for the information Craig :) .

Luckily I do not need to change any script. I just needed to get information from the script to do my thing.

Regards,

Paul

Post Reply

Return to “Talking LiveCode”