Page 1 of 2

first char of stack

Posted: Wed Aug 28, 2013 9:00 am
by pascalh4
Hi

Another small issue

Is it possible to identify a stack with only the first charater of the name

eg literally:
stack whose first character begins with an L.

Pascal

Re: first char of stack

Posted: Wed Aug 28, 2013 12:44 pm
by Klaus
Hi Pascal,

this is more a logical that a Livecode problem :)

Programming is about finding a solutiuon to a logical problem first and THEN
translate this solution to a language that your machine will understand.

Try to solve the problem WITHOUT a computer first, instead pretend to only have
a piece of paper, with a list of (stack) names on it***, one name per line, and a pencil.

' This list is MANDATORY for this problem!

Now how do you elimintate all nems (lines) that do not begin with an L?

Exactly, you can
1. strike out all names/lines that do NOT begin with an L
or
2. immediately pick the name that begins with L

Well, this is the problem and its solution, now you need to translate this into Livecode.
Hints: Use filter (1) or "lineoffset" (2) to extract the correct LINE from your list :-)

Check also my little "Memory" stack to see another example of this "real life" logical approach to a problem:
http://www.major-k.de/xtalk.html
Scroll down to "simple_memory1"


Best

Klaus

Re: first char of stack

Posted: Wed Aug 28, 2013 1:37 pm
by pascalh4
Hi Klaus

It is true that I was not very accurate.

I'm still working on the links between stacks them.

I seek only the means to go to a stack whose first Character name is a L.

For the proposed link to
Check also my little "Memory" stack to see another example of this "real life" logical approach to a problem:
Sorry, i can't read files with .mc

Pascal

Re: first char of stack

Posted: Wed Aug 28, 2013 2:42 pm
by FourthWorld
pascalh4 wrote:Sorry, i can't read files with .mc
In LC, use File->Open Stack.

While double-clicking a .mc file may not always launch LC, the filters used in the menu item include .mc in both the Commercial and Community editions.

Re: first char of stack

Posted: Wed Aug 28, 2013 3:51 pm
by Klaus
Yep, or simply change the MC file suffix to REV or LIVECODE :D

Re: first char of stack

Posted: Wed Aug 28, 2013 4:12 pm
by pascalh4
hi

Thank you I opened the file, I will read it and see if " je trouve mon bonheur". (French expression that means: I find what I want)


and for the topic "text adapt", can you advise me where to look.

Pascal.

Re: first char of stack

Posted: Wed Aug 28, 2013 4:22 pm
by Klaus
Bonjour Pascal.

OK, to be clear, my little Memory stack has nothing to do with your current problem here!

Did you understand my example with a piece of paper & pencil? No?


Best

Klaus

Re: first char of stack

Posted: Wed Aug 28, 2013 11:44 pm
by pascalh4
hi late, ... or early

yes I think I understand.

The cutting portion of reasoning help me to code better.

In your example, this is more difficult for me, but I understood the logic of progress.

Back to my problem: Identifying by the first character of a stack, allows me to create a loop for copying, in two mainstack (the first character as constant and the other characters, numbers, allows me to classify the stack: with the principle discussed in the topic "previous next stack")

Soon

Pascal

Re: first char of stack

Posted: Thu Aug 29, 2013 12:17 am
by BvG
there' s the "begins with" modifier that you can use with an if statement.

Re: first char of stack

Posted: Thu Aug 29, 2013 7:42 am
by pascalh4
Hi,

Thank you for that, but I still can not write a decent script.

Here's what I want to do:

given:
Mainstack, name "Base" with button
Substack, name "L ...."

Action:
Button click , into stack "Base", go to stack begins with "L"

Here's what I wrote:

Code: Select all

on mouseUp
   if name of stack into this stack begins with "S" then
      go to stack it
      end if
end mouseUp
it does not work.

Code: Select all

if name of stack into this stack begins with "S" then
on mouseUp   
   go to stack it
end mouseUp
   end if
that either.

For you, the error must be clear.
But not for me.
Can you tell me, where to find explanations that help me.

Pascal

Re: first char of stack

Posted: Thu Aug 29, 2013 10:18 am
by BvG
in the help menu, there's an entry called "user guide". It opens a pdf. I suggest you read that.

Re: first char of stack

Posted: Thu Aug 29, 2013 11:27 am
by pascalh4
hi,

I've downloaded it and I've looked, but the chapter 5.7.1 "If ... then ... else" doesn't help me much.

Pascal

Re: first char of stack

Posted: Thu Aug 29, 2013 12:48 pm
by Klaus
Hi Pascal,

what Björnke means, is that you are missing the most basic things of Livecde
but they are very neccessary to be able to use Livecode!
if name of stack into this stack begins with "S" then

Do not use any syntax if you are not sure what it does, or if it even exists! 8)

Check these stacks to get the basics about stacks, substacks, cards, objects etc...:

Code: Select all

http://www.hyperactivesw.com/revscriptconf/scriptingconferences.html
Please do in you own interest!


OK, I will explain the "real life" analogy from my first posting here:
1. The list of stacks is MANDATORY as I wrote, and I guess you mean the SUBSTACKS** of your mainstack, right?
** C'est le mot magique ici! :-)

The you can:
...
put the substacks of stack"Base" into tSubStackList
## Now you have a CR delimited list of all the substacks of your mainstack (Base) in the variable
...

2. See which of these lines start with an L or whatever character:
...
put "L" into tFirstCharacter
## You can use LINEOFFSET or FILTER
## I use FILTER here, which will remove ALL lines that do NOT begin with that character
filter tSubStackList with (tFirstCharacter & "*")

## If you have prepared everything correctly (NOT 2 substacks with the same first character in name etc...) you can now:
go stack tSubStackList
## the list should only contain ONE line -> the name of the substack that begins with L
...

3. Now all together for your button script:

Code: Select all

on mouseup
   put the substacks of stack"Base" into tSubStackList
   put "L" into tFirstCharacter
   filter tSubStackList with ("*" & tFirstCharacter)

   ## Better check once to much thatn getting an error!
   if tSubStackList = empty then
       exit mouseup
   end if

   ## Finally go to the stack:
   go stack tSubStackList
end mouseup
See how the logical principles of "real life" can be "tranlsated" into Livecode easily?
But you need to analyze and understand them first AND to underatand the language
of Livecode to be able to tranlate them at all!!

If you do not know the word for that round leather thing that you can kick with your foot,
then you cannot translate it into another language :-D

Try to digest and UNDERSTAND what I am doing here.

After you "got" it, we will create a FUNCTION for this,
where you only need to supply the first desired chracter.
But not now! :D


Best

Klaus

Re: first char of stack

Posted: Thu Aug 29, 2013 1:51 pm
by pascalh4
Thank you to everyone and everything

I'll try (mouliner) dissect these informations.

I also downloaded LC University PE, I think the explanation is quite simple (and it's good for my spoken English, too). If it suits me, I buy a full version.

Soon
But now I think I have (du boulot sur la planche) work to be done.

Pascal

Re: first char of stack

Posted: Thu Aug 29, 2013 2:24 pm
by pascalh4
Hi Klaus
If you have prepared everything correctly (NOT 2 substacks with the same first character in name etc...) you can now:
not 2 with the same first character in name

or not 2 with the same name ?

If I can not use more than once substack with the same first character, there is no point to take it as a reference! No?

## I use FILTER here, which will remove ALL lines that do NOT begin with that character
filter tSubStackList with (tFirstCharacter & "*")
In your code
on mouseup
put the substacks of stack"Base" into tSubStackList
put "L" into tFirstCharacter
filter tSubStackList with ("*" & tFirstCharacter)

Is it the variable that we must place first (as in the explanation and not the code)?

Pascal