how to get the NEXT and PREVIOUS buttons to work

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
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

how to get the NEXT and PREVIOUS buttons to work

Post by keram » Sat Nov 16, 2013 3:52 am

Hello,

I'm completely new to programming in LiveCode and in general so please bear with me if my questions are very basic. I read through the LiveCode user manual, but it's not so easy to grasp some things and learn from it.

I created a stack to combine text from 3 different files and to show each line of text at a time. To show the first line and the last line was easy, but to get the NEXT and PREVIOUS buttons to work is not easy - I'm missing something.

for the NEXT button:

Code: Select all

global text2display
on mouseUp
   put fld "showingLine" into currentLine
   add 1 to currentLine
   put currentLine into fld "text2display"
end mouseUp

for the PREVIOUS button:

Code: Select all

global text2display
on mouseUp
   put fld "showingLine" into currentLine
   subtract 1 from currentLine
   put currentLine into fld "text2display"
end mouseUp
Also I'd like to show the number of the current line.

I'm attaching the stack.

Thanks for any help with this.

keram
Attachments
next-previous-line.zip
(10.45 KiB) Downloaded 208 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: how to get the NEXT and PREVIOUS buttons to work

Post by dunbarx » Sat Nov 16, 2013 6:04 am

Hi.

You are off to a good start. You have made a stack and are struggling with it. This is good.

Does field "showingLine" contain a number? If so, then putting it into a variable and then adding 1 to it is fine. But then it looks like you want to display that incremented line of something into fld "text2display". What is that "something"? It looks like the incremented number itself will appear in fld "text2Display".

So we have a syntax error and a structural error.

You wrote: put currentLine into fld "text2display"

You likely wanted to say: put line currentLine of something into fld "text2display", ("something" could be a field or a variable)

Do you see? currentline is a number (I hope) so "line currentLine" might resolve to, say, "line 3" and then it ought to read "line 3 of field "yourField". This now makes sense. In your script, did you get a number in fld "text2Display"?

The same holds for the second handler, which follows nicely the thinking of the first. But we have to find out what is going on. How do you get the three files into the stack, and where is the text stored? Is that place the "something" of which I spoke? Write back. I could not make much of your stack.

Craig Newman

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to get the NEXT and PREVIOUS buttons to work

Post by keram » Sat Nov 16, 2013 9:53 am

Hi Craig,

Thanks for your quick response and encouragement :)
I could not make much of your stack.
Sorry, it's my fault.
I created a stack that imported 3 text files from the same folder that the stack was placed in. Then I thought that these files were kind of "baked" into the stack, but it apparently it's not the case.

But now I imported these 3 text files into a second card, cd "files", so the text should be visible now.

The "something" that you are mentioning is the variable gtext2display.

The improved stack is now showing the first and last line but still not showing the NEXT and PREVIOUS:

code on the card:

Code: Select all

global gtext2display
on openCard
   put empty into gtext2display
   put fld "Field 1" of cd "files" after gtext2display
   put fld "Field 2" of cd "files" after gtext2display
   put fld "Field 3" of cd "files" after gtext2display
   
   put empty into fld "text2display"
   put 0 into fld "showingLine"
   put the number of lines in gtext2display into fld "numberOfLines"
end openCard
for the NEXT button:

Code: Select all

global gtext2display
on mouseUp
   put fld "showingLine" into currentLine
   add 1 to currentLine
   put line currentLine of gtext2display into fld "text2display"
   put line number of currentLine into fld "showingLine"
end mouseUp
for the PREVIOUS button:

Code: Select all

global gtext2display
on mouseUp
   put fld "showingLine" into currentLine
   subtract 1 from currentLine
   put line currentLine of gtext2display into fld "text2display"
   put line number of currentLine into fld "showingLine"
end mouseUp
I'm attaching the stack as well.

keram
Attachments
next-previous-line.zip
(10.51 KiB) Downloaded 190 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: how to get the NEXT and PREVIOUS buttons to work

Post by chris25 » Sat Nov 16, 2013 10:56 am

Hallo Keram, firstly, I know nothing, I'm just a beginner and since I have no idea what you are trying to achieve I can not visualize what your mental plan is with all this. However I did look at your stack with interest and noticed a couple of things. Firstly on your button one (both of them) line 6 there is a bad compilation error (expression bad factor), since I have never found a "dictionary of fault terminology" in LC I have no idea what this means except to say that there is something wrong in this line. Secondly you have named all your buttons the same, this is never a good idea, since you will get conflicts eventually and already when you double click on one button with the non-browser arrow to edit in order see the properties inspector it brings up two inspectors...awkward, thirdly I saw that the buttons were deep underground, I mean really deep - nested under 4 groups. While I do not know if this is really ever an issue, I might imagine that to have so many nested groups within each other to be perhaps not so good I personally would try to avoid this sort of thing. I am sure Craig or someone else will deny or confirm this. So I hope that there is something here that might help in the meantime, while waiting for the professionals to wake up on the other side of the world. :)

As I said, sorry I can not help you, but consider this an introduction and welcome, I will follow what you are doing because this is something that I have not covered yet.
Kind regards
chris

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to get the NEXT and PREVIOUS buttons to work

Post by keram » Sat Nov 16, 2013 11:24 am

Hi Chris,

Thanks for your comments. They were useful. And, yes, you know quite a lot - I've noticed you've been posting lots of messages...

I have changed the names of the button images now to Image 1 ...Image 4, but I cannot find that nesting you are mentioning. The four buttons are grouped.
As far as the error, I have no idea what it means and how to correct it.

The plan is to make a stack for displaying one line of text at a time by clicking on NEXT (PREVIOUS) button and later on I want to add automatic display as well which I want to set timing on (every hour for example or at a specific time of the day).
But since I'm a complete beginner I have to take it step by step. I hope that the PRO guys here will not mind to offer some help once I notice my head is hurting from banging against the wall :wink:
But I really want to learn LC as much as possible. I wish there would be some really good tutorial with lots of practical examples and thorough explanations.

Attached is the corrected stack (corrected image names).

keram
Attachments
next-previous-line.zip
(corrected image names)
(10.41 KiB) Downloaded 204 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: how to get the NEXT and PREVIOUS buttons to work

Post by chris25 » Sat Nov 16, 2013 11:49 am

very quickly you caught me as I was going out so won't be back for a few hours. Will take a look and point you to a number of areas where there are some interesting tutorials you might like when i return
chris

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to get the NEXT and PREVIOUS buttons to work

Post by Klaus » Sat Nov 16, 2013 12:58 pm

Hi keram,

here a working version of your stack.
I fixed and commented all scripts, so take a deep look :D


Best

Klaus
Attachments
next-previous-line_2.livecode.zip
Working stack
(11.18 KiB) Downloaded 210 times

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: how to get the NEXT and PREVIOUS buttons to work

Post by chris25 » Sat Nov 16, 2013 2:01 pm

I appreciate this as well Klaus - thanks

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: how to get the NEXT and PREVIOUS buttons to work

Post by chris25 » Sat Nov 16, 2013 2:08 pm

Keram, just thought I would post a handful of little goodies, I am sure you will find something here. The last one is a particularly helpful introduction visually to basics. Kindest Regards, chris.

http://livecodesupersite.com/tutorials.html

http://livecode.wikia.com/wiki/Livecode_Wiki

http://livecode.byu.edu/indexgeneric.php

http://revonline.runrev.com/

http://www.hyperactivesw.com/revscriptc ... ences.html

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: how to get the NEXT and PREVIOUS buttons to work

Post by keram » Sat Nov 16, 2013 5:23 pm

Hi Klaus,

Thank you so much for your help!
I'll definitely will take a deep look at your corrections.

Also thanks to you, Chris, for the links - I'll check them out tomorrow.

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

Post Reply