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: 744
Joined: Thu Sep 11, 2014 1:49 pm

Find a string in a stack card object script code

Post by mrcoollion »

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: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod »

Hi Paul,
Did you use Find/replace tools ?
Best regards
Jean-Marc
https://alternatic.ch
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 »

FR.png
F&R.png
mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

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

Post by mrcoollion »

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: 2734
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

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

Post by jmburnod »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx »

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: 10415
Joined: Fri Feb 19, 2010 10:17 am

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

Post by richmond62 »

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: 744
Joined: Thu Sep 11, 2014 1:49 pm

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

Post by mrcoollion »

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: 744
Joined: Thu Sep 11, 2014 1:49 pm

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

Post by mrcoollion »

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: 744
Joined: Thu Sep 11, 2014 1:49 pm

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

Post by mrcoollion »

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: 10501
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx »

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: 744
Joined: Thu Sep 11, 2014 1:49 pm

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

Post by mrcoollion »

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