next & previous with 2 buttons

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
brandcode
Posts: 28
Joined: Mon Dec 01, 2014 12:28 pm

next & previous with 2 buttons

Post by brandcode » Tue Dec 30, 2014 9:52 pm

hi.
I don't know if this question have answered before,i have use the search button but i don't find anything..
i have 2 buttons next and previous,and in the same card i have some groups to show some infos.
is possible to cycle this groups back and forward with the buttons (next-Previous) ?
thank you..

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: next & previous with 2 buttons

Post by magice » Tue Dec 30, 2014 11:19 pm

in next button

Code: Select all

on mouseUp
   go to cd(the number of this cd+1)
end mouseUp
in previous button

Code: Select all

on mouseUp
   go to cd(the number of this cd-1)
end mouseUp

brandcode
Posts: 28
Joined: Mon Dec 01, 2014 12:28 pm

Re: next & previous with 2 buttons

Post by brandcode » Tue Dec 30, 2014 11:28 pm

thank you magice..
I know how to go between card's,i don't want to change cards i want to change the groups that exist in the card like slide

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: next & previous with 2 buttons

Post by jmburnod » Tue Dec 30, 2014 11:36 pm

Hi brandcode,

You have to create a global or local variable to store the current group
Something like that:

Code: Select all

local sGroupName,sCurrentGroup
on opencard
   put "myGroup1,myGroup2,myGroup3" into sGroupName
   repeat for each item tGroup in sGroupName
      hide group tGroup
   end repeat
   put 1 into sCurrentGroup
   doShowMyGroup
end opencard

on goNextGrp
   if sCurrentGroup = the num of items of sGroupName then 
      beep
      exit goNextGrp
   end if
   doHideCurrentGrp
   add 1 to sCurrentGroup
   doShowMyGroup
end goNextGrp

on goPrevGrp   
   if sCurrentGroup = 1  then
      beep
      exit goPrevGrp
   end if
   doHideCurrentGrp
   subtract 1 from sCurrentGroup
   doShowMyGroup
end goPrevGrp

on doShowMyGroup
   show group (item sCurrentGroup of sGroupName)
end doShowMyGroup

on doHideCurrentGrp
   hide group (item sCurrentGroup of sGroupName)
end doHideCurrentGrp
Best regards
Jean-Marc
https://alternatic.ch

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: next & previous with 2 buttons

Post by SparkOut » Tue Dec 30, 2014 11:38 pm

You can do a number of things. One very simple way would be to

Code: Select all

set the visible of group "slideOne to false
Set the visible of group "slideTwo" to true
you can get more stylish by locking the screen for visual effect and unlocking again to deliver that effect-you can also apply the effect to just the part of the screen, but that's a bit hard to check and explain while just using this phone at the moment.

brandcode
Posts: 28
Joined: Mon Dec 01, 2014 12:28 pm

Re: next & previous with 2 buttons

Post by brandcode » Tue Dec 30, 2014 11:39 pm

jmburnod wrote:Hi brandcode,

You have to create a global or local variable to store the current group
Something like that:

Code: Select all

local sGroupName,sCurrentGroup
on opencard
   put "myGroup1,myGroup2,myGroup3" into sGroupName
   repeat for each item tGroup in sGroupName
      hide group tGroup
   end repeat
   put 1 into sCurrentGroup
   doShowMyGroup
end opencard

on goNextGrp
   if sCurrentGroup = the num of items of sGroupName then 
      beep
      exit goNextGrp
   end if
   doHideCurrentGrp
   add 1 to sCurrentGroup
   doShowMyGroup
end goNextGrp

on goPrevGrp   
   if sCurrentGroup = 1  then
      beep
      exit goPrevGrp
   end if
   doHideCurrentGrp
   subtract 1 from sCurrentGroup
   doShowMyGroup
end goPrevGrp

on doShowMyGroup
   show group (item sCurrentGroup of sGroupName)
end doShowMyGroup

on doHideCurrentGrp
   hide group (item sCurrentGroup of sGroupName)
end doHideCurrentGrp
Best regards
Jean-Marc
thank you jmburnod and sparkout
i am sure i have long way to learn..thank you for point me the right way

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

Re: next & previous with 2 buttons

Post by dunbarx » Wed Dec 31, 2014 12:20 am

Hi.

Do you want to hide all the groups but the current one of interest? Or just hilite that group in some way, to set it apart visually? In either case, the solution is simple and fun.

Where are you with LC? How long have you been working with it? Have you written any handlers on your own yet? Please write back, and we will give you a good running start.

Craig Newman

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

Re: next & previous with 2 buttons

Post by dunbarx » Wed Dec 31, 2014 3:53 pm

Hi again.

Here is an experiment for you:

On a new card make five buttons. Name them "Next", "xx1", "xx2" and "xx3" and "xx4".

In the script of btn "next":

Code: Select all

on mouseUp
   repeat with y = 1 to the number of btns
      if the name of btn y contains "XX" and the visible of btn y then
         hide btn y
         show btn (y+1)
         exit to top
      end if
   end repeat
end mouseUp
Now hide btns "xx2", "xx3" and "xx4". Only "xx1" and "next" should be visible. Click on the "next" button. Simple, eh? But what happens after the fourth click? How can we fix this? Can you write the handler for a new button that you will name "previous"? Will the same sort of problem exist there as well? To make your life easier while playing, you might want to make yet another button that shows all the buttons, or maybe hides all the "xx" buttons but one. You will learn a lot just making tools that allow you to work out the actual issues with your project.

Get going.

Craig

Post Reply