Using the card number

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
calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Using the card number

Post by calmrr3 » Sat Nov 09, 2013 2:12 am

I have a map that shows the location of the user within the stack. Each card is represented by a dot which changes to yellow when you are on that card.

Is there a way of getting the card number and using that to target a dot to change its colour? For example: On card number 5 change the colour of "dot5" to yellow.

I had a go at guessing the script to be applied to the map (it is a group placed on each card).. but it doesnt work. Thank you

Code: Select all

on opencard 
   put the cardNumber of this card into cardNumber 
    set the backgroundColor of "dot & cardNumber"  to yellow
end opencard

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Using the card number

Post by Simon » Sat Nov 09, 2013 2:23 am

Try this:
put the name of this card
Now when you work with this card "1" will show up so you'll have to get word 2 of the answer, but more, then you must remove the quotes. You'll see what I mean.

Now better stuff for you:
Start using behaviors... I expect each card will have the same script? Just like not putting multiple copies of the same image on you cards you can use behaviors to have a single storage place for the script.
If that is of interest to you and you don't know how to use behaviors then just ask.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

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

Re: Using the card number

Post by dunbarx » Sat Nov 09, 2013 5:54 am

Simon has thrown down the gauntlet. Do try what he suggests.

Going back just a bit, there is no native word "cardNumber". Your handler would make LC interpret that as a custom property. It would not throw an error, since it would take that path.

What you wanted was "the number of this card". "Number" is a native property.

Craig

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

Re: Using the card number

Post by Klaus » Sat Nov 09, 2013 12:37 pm

Hi calmrr3,
calmrr3 wrote:

Code: Select all

on opencard 
   put the cardNumber of this card into cardNumber 
   set the backgroundColor of "dot & cardNumber"  to yellow
end opencard
OK, we know now "the number of this cd" is the correct syntax, lets check the second line of your script:
1. You need to address any object with its TYPE, too!
So what are your DOTs?
Graphics, buttons, images,fields, what?
I assume BUTTON here:
...
set the backgroundcolor OF BUTTON xyz to ...
...
2. When concatenating object names you need to put this concatenation into parens,
since the engien will first evaluate the things INSIDE the parens!

So the working script should look like this:

Code: Select all

on opencard 
   put the number of this card into cardNumber 
   set the backgroundColor of BUTTON ("dot" & cardNumber)  to yellow
end opencard
Best

Klaus

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using the card number

Post by calmrr3 » Sat Nov 09, 2013 1:32 pm

Thank you all,

I've managed to get it working using your help :)

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using the card number

Post by calmrr3 » Sat Nov 09, 2013 6:56 pm

On last question on this subject:

When moving from one card to another, the dots (made with the oval tool) are staying yellow.
Is there a way of making only the current dot (card) yellow?

The way I have been trying is as follows:
I don't know the correct syntax for the last visited card (I didnt use 'previous card' because I wasnt sure if that only goes to the card with card number one less than the current card) In the case of this app the number of the last card visited is not necessarily the current card number -1.
I.E the current card number could be 7 but the last card visited could be 4.

Code: Select all

on opencard 
      put the number of this card into cardNumber 
      put the number of the last visited card into PreviousCardNumber 
      
      set the backgroundColor of grc("dot" & cardNumber)  to yellow
      if cardNumber > 1 then
      set the backgroundColor of grc("dot" & PreviousCardNumber)  to black
      end if
end opencard

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

Re: Using the card number

Post by jmburnod » Sat Nov 09, 2013 7:17 pm

Hi calmrr3
I don't know the correct syntax for the last visited
Check "push" and "pop" on the dictionary.

Or
use customProp of the destination cd to store the name of the start cd
Something like that:

Code: Select all

on goMyCd pDestCd
   set the uMyProvCD of cd pDestCd to (the short name of this cd)
   go to cd pDestCd
end goMyCd

on goBack
   go to cd (the uMyProvCD of this cd)
   set the uMyProvCD of this cd to empty 
end goBack
Best regards
Jean-Marc
https://alternatic.ch

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using the card number

Post by calmrr3 » Sat Nov 09, 2013 8:40 pm

Hi Jean-Marc

Code: Select all

on goMyCd pDestCd
   set the uMyProvCD of cd pDestCd to (the short name of this cd)
   go to cd pDestCd
end goMyCd

on goBack
   go to cd (the uMyProvCD of this cd)
   set the uMyProvCD of this cd to empty 
end goBack
This may be a silly question but, what do the lower case 'p' and the lower case 'u' stand for when placed before 'pDestCd' & "uMyProvCD"

and also, what do 'pDestCd' & "uMyProvCD" mean? Thanks!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Using the card number

Post by jacque » Sat Nov 09, 2013 9:02 pm

calmrr3 wrote: I don't know the correct syntax for the last visited card (I didnt use 'previous card' because I wasnt sure if that only goes to the card with card number one less than the current card) In the case of this app the number of the last card visited is not necessarily the current card number -1.
I.E the current card number could be 7 but the last card visited could be 4.
The "previous" keyword always means the card with one less number than the current card, so you are safe to use that. (Likewise, the "next" card is always the one with the next-higher card number.) If you want to find out the last-visited card, you have to look at the recentCards property. Or easier, you can use the "go back" command, which also goes to the last-visited card regardless of its numerical sequence.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Using the card number

Post by jmburnod » Sat Nov 09, 2013 10:25 pm

Hi calrr3
This may be a silly question but, what do the lower case 'p' and the lower case 'u' stand for when placed before 'pDestCd' & "uMyProvCD"
That is conventions:
"p" for param and "u" for customprop
and also, what do 'pDestCd' & "uMyProvCD" mean? Thanks!
pDestCd = destination card
uMyProvCD = the current cd
https://alternatic.ch

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Using the card number

Post by FourthWorld » Sat Nov 09, 2013 11:03 pm

FWIW, the rationale behind those variable naming conventions are documented here, along with other scripting tips:

Fourth World Scripting Style Guide
Helpful tips for xTalk, ActionScript, JavaScript and other scripting languages
http://www.fourthworld.com/embassy/arti ... style.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

calmrr3
Posts: 100
Joined: Mon Oct 28, 2013 2:39 pm

Re: Using the card number

Post by calmrr3 » Mon Nov 11, 2013 5:20 pm

Thanks everyone,

Is there a way of selecting all dots (dot1 up to dot27)?

Code: Select all

set the backgroundColor of grc("dot" & x )  to black
x would just be any number value (could be dot2, dot5, dot8 etc etc)

Thanks again

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

Re: Using the card number

Post by dunbarx » Mon Nov 11, 2013 5:29 pm

Hi.

Think about the property "the number of graphics". This will return, well, the number of graphics. If you add a few or delete a few, do you see that this same function will always give the correct number?

That said, can you form a repeat loop, using the "repeat with" form, that uses this to advantage? Your previous post had the hard part right there.

One caveat. If there are other graphics on the card besides the 1-27 you are interested in, you must filter those out of your loop. Not sure if this is the case, and even if not, it leaves a little trap in the stack if you ever do decide that another graphic would be useful. In that case, you must find a way to isolate the graphics in the special "group" you are working with. This might be done by a naming convention (grc dot1, grc dot2, etc) Again, you seem to be already there...

Write back if you need help, but writing this handler yourself is, in my opinion, one of the best possible learning exercises you could ever do. It is a technique you will use for the rest of your life.

Craig

Post Reply