Page 1 of 1

Using the card number

Posted: Sat Nov 09, 2013 2:12 am
by calmrr3
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

Re: Using the card number

Posted: Sat Nov 09, 2013 2:23 am
by Simon
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

Re: Using the card number

Posted: Sat Nov 09, 2013 5:54 am
by dunbarx
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

Re: Using the card number

Posted: Sat Nov 09, 2013 12:37 pm
by Klaus
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

Re: Using the card number

Posted: Sat Nov 09, 2013 1:32 pm
by calmrr3
Thank you all,

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

Re: Using the card number

Posted: Sat Nov 09, 2013 6:56 pm
by calmrr3
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

Re: Using the card number

Posted: Sat Nov 09, 2013 7:17 pm
by jmburnod
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

Re: Using the card number

Posted: Sat Nov 09, 2013 8:40 pm
by calmrr3
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!

Re: Using the card number

Posted: Sat Nov 09, 2013 9:02 pm
by jacque
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.

Re: Using the card number

Posted: Sat Nov 09, 2013 10:25 pm
by jmburnod
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

Re: Using the card number

Posted: Sat Nov 09, 2013 11:03 pm
by FourthWorld
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

Re: Using the card number

Posted: Mon Nov 11, 2013 5:20 pm
by calmrr3
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

Re: Using the card number

Posted: Mon Nov 11, 2013 5:29 pm
by dunbarx
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