Page 1 of 1

Button script

Posted: Mon Nov 11, 2013 1:00 pm
by calmrr3
I have 3 buttons, they appear on every card as a group. The script applied to each of the buttons is as follows( the go to card" parts are different on each button but this is the general structure):

Code: Select all

on mouseUp

   put the number of this card into thisCardNumber
   put the number of the previous card into lastCardNumber
   
   if thisCardNumber is 1 then go to card "card2"
    set the backgroundColor of "dot & lastCardNumber" to black
    if thisCardNumber is 2 then go to card "card5"
     set the backgroundColor of "dot & lastCardNumber" to black
     if thisCardNumber is 3 then go to card "card1" --gameover
      set the backgroundColor of "dot & lastCardNumber" to black
      if thisCardNumber is 4 then go to card "card7"
       set the backgroundColor of "dot & lastCardNumber" to black
       if thisCardNumber is 5 then go to card "card8"
        set the backgroundColor of "dot & lastCardNumber" to black
        if thisCardNumber is 6 then go to card "card10"
         set the backgroundColor of "dot & lastCardNumber" to black
         if thisCardNumber is 7 then go to card "card11"
          set the backgroundColor of "dot & lastCardNumber" to black
          if thisCardNumber is 8 then go to card "card12"
           set the backgroundColor of "dot & lastCardNumber" to black
           if thisCardNumber is 9 then go to card "card6"
            set the backgroundColor of "dot & lastCardNumber" to black
            if thisCardNumber is 10 then go to card "card13"
             set the backgroundColor of "dot & lastCardNumber" to black
             if thisCardNumber is 11 then go to card "card14" 
              set the backgroundColor of "dot & lastCardNumber" to black
              if thisCardNumber is 12 then go to card "card1"--gameover
               set the backgroundColor of "dot & lastCardNumber" to black
               if thisCardNumber is 13 then go to card "card16"
                set the backgroundColor of "dot & lastCardNumber" to black
                if thisCardNumber is 14 then go to card "card1"--gameover
                 set the backgroundColor of "dot & lastCardNumber" to black
                 if thisCardNumber is 15 then go to card "card17"
                  set the backgroundColor of "dot & lastCardNumber" to black
                  if thisCardNumber is 16 then go to card "card1"--gameover
                   set the backgroundColor of "dot & lastCardNumber" to black
                   if thisCardNumber is 17 then go to card "card1"--gameover
                    set the backgroundColor of "dot & lastCardNumber" to black
                    if thisCardNumber is 18 then go to card "card19"
                     set the backgroundColor of "dot & lastCardNumber" to black
                     if thisCardNumber is 19 then go to card "card1"--gameover
                      set the backgroundColor of "dot & lastCardNumber" to black
                      if thisCardNumber is 20 then go to card "card21"
                       set the backgroundColor of "dot & lastCardNumber" to black
                       if thisCardNumber is 21 then go to card "card1"--gameover
                        set the backgroundColor of "dot & lastCardNumber" to black
                        if thisCardNumber is 22 then go to card "card23"
                         set the backgroundColor of "dot & lastCardNumber" to black
                         if thisCardNumber is 23 then go to card "card25"
                          set the backgroundColor of "dot & lastCardNumber" to black
                          if thisCardNumber is 24 then go to card "card18"
                           set the backgroundColor of "dot & lastCardNumber" to black
                           if thisCardNumber is 25 then go to card "card1"--gameover
                            set the backgroundColor of "dot & lastCardNumber" to black
                            if thisCardNumber is 26 then go to card "card1"--complete
                             set the backgroundColor of "dot & lastCardNumber" to black

end mouseUp
Image

Each dot represents a card. The current card is shown by a yellow dot, however when I go back to card 1 the visited dots remain yellow, rather than changing back to black.
Also the following alert is coming up when i click the button:
Type Chunk: error in object expression
Object 1
Line set the backgroundColor of "dot & lastCardNumber" to black
Hint dot & lastCardNumber

Re: Button script

Posted: Mon Nov 11, 2013 1:25 pm
by Traxgeek
Hi Calmrr3,

As I understand it, 'Previous' (as in 'previous card' ) simply refers to the card number before the card number you are currently on.

ie - if you're on card 8 then the 'previous card' will (always) be card 7 regardless of whether you came to the current card (8) from card 5 as your logic (If then statement group) would imply.

Effectively, your code simply makes the dot for the card number (current card number - 1 or if < 1 then the last card of the stack / the highest numbered card) black whereas I think you mean to make the dot for the last card visited black.
Maybe I'm not explaining that too well... say you're on card 11, your logic indicates you can only arrive here via card 7 BUT your logic resets the colour of the dot for card 11-1 (=10) not the dot for card 7.

Does this help ? If not, explain a little more, and I'll revert.

Regards.

Re: Button script

Posted: Mon Nov 11, 2013 1:34 pm
by calmrr3
Hi, yes you are right!

Thanks

EDIT: how do I replace the last card with last card visited?
Could I just set all the dots to black on card close so that only the card number of the next card is yellow?
Or could I replace last card with recent card?

Re: Button script

Posted: Mon Nov 11, 2013 3:04 pm
by dunbarx
Hi.

If ever a handler called for a "switch" control structure, this one does. Do you know how to set that up? Please read about this in the dictionary. As a starter, think about this:

Code: Select all

put the number of this card into thisCardNumber
      put the number of the previous card into lastCardNumber
   
   switch thisCardNumber
      case 1
         go cd "card2"
           set the backgroundColor of "dot & lastCardNumber" to black
         break
      case 2
         go to card "card5"
         set the backgroundColor of "dot & lastCardNumber" to black
         break
      case 3
      case 12
      case 14
      case 16
      case 17
      case 19
      case 21
      case 25
         go to card "card1"
         set the backgroundColor of "dot & lastCardNumber" to black
         break
   end switch
It is another way of separating conditionals. Note the succession of "case" statements in the middle of the code snippet. These are all pointing to the same result, and need not be duplicated as they are in your repeat thing.

Craig Newman

Re: Button script

Posted: Mon Nov 11, 2013 3:49 pm
by Traxgeek
Hi Calmrr3,

Hmmm... I seem to remember battling with this for a while. I came up with two CustomProperties but these could just as easily be global variables...
For simplicity here, I'll stick to globals - you can easily change these for CustomProperties if you like... but, for now...

Two variables are required - 'ThisCard' and 'LastCard' (well, it's easier to debug with the 2 but only the one is needed)
Before populating 'ThisCard' put 'ThisCard' into 'LastCard' then put the number of the current card into 'ThisCard'

Startup / Stack script (pseudo-code) :
put the number of the first card you want to display into 'ThisCard'
Display the card (that matches 'ThisCard')

When entering a card (pseudo-code) :
put 'ThisCard' into 'LastCard'
put the number of this card into 'ThisCard'
clear / empty the colour for the card 'LastCard'
colour / make yellow the dot for the card 'ThisCard'

That would do it... although I can already think of ways to make this simpler...
Of course, as Dubarx says, your nested 'IFs' don't make life easy... try the switch structure for items like this... (although maybe this was just a 'proof' of concept' thing... anyway...) Anyway, over to you...

HTH.

Regards.

EDIT
I forgot you're using a centralised piece of code to handle card changes. Dunbarx's code is cool and better suited - for me, I handled card exits from within each card so needed a slightly different approach...

Re: Button script

Posted: Mon Nov 11, 2013 7:25 pm
by jacque
The "recentCards" property keeps a list of all recently visited cards. Unless you want to disallow some of the cards in that list, you don't need to make your own list.

During development, recentCards will contain cards in IDE stacks, but in a standalone it will include only your own cards.

Re: Button script

Posted: Tue Nov 12, 2013 8:34 pm
by calmrr3
The go recent card form goes to the most recently visited card.
- http://docs.runrev.com/Command/go

With this in mind could I do this:

Code: Select all

 on opencard 

   lock screen for visual effect
   put the number of this card into cardNumber
   put the number of recent card into lastVisited 
   set the backgroundColor of grc("dot" & cardNumber)  to white
   set the height grc("dot" & cardNumber) to 20
   set the width grc("dot" & cardNumber) to 20
   unlock screen with visual effect dissolve 
   lock screen for visual effect
  set the height grc("dot" & cardNumber) to 10
  set the width grc("dot" & cardNumber) to 10
  set the backgroundColor of grc("dot" & cardNumber)  to "#030303"
  unlock screen with visual effect dissolve very fast
  set the backgroundColor of grc("line"  lastVisited &  "to" & cardNumber )  to white
     
end opencard
The part I am trying to sort out at the moment is:

Code: Select all

put the number of this card into cardNumber
   put the number of recent card into lastVisited 
set the backgroundColor of grc("line"  lastVisited &  "to" & cardNumber )  to white
So I could name a graphic "line1 to 2" i.e line from dot 1 to dot 2, like so:

Image

OR would I be better using points to draw a line between the locations of the dots?

I would like the outcome of this to be: When a new card is opened the corresponding dot number fades in to white ( THE BACKGROUND IS BLACK). Then when the user advances the next dot fades to white as does the line joining the two dots.

Sorry I keep on changing my idea! Thanks again

Callum

Re: Button script

Posted: Wed Nov 13, 2013 12:56 am
by dunbarx
Set two points of a line graphic to the locs of the two dots.

Craig

Re: Button script

Posted: Fri Nov 15, 2013 8:53 pm
by calmrr3
Something like this?

Code: Select all

on cardOpen
   put the number of this card into cardNumber
   put the number of recent card into lastVisited 
   
   set the backgroundColor of grc ("dot" & cardNumber) to yellow
   set the points of graphic "line" to the loc of graphic ("dot" & lastVisited) & return & the loc of graphic ("dot" & cardNumber)
   set the borderColor of grc "line" to yellow
   
   end cardOpen

Re: Button script

Posted: Fri Nov 15, 2013 9:05 pm
by dunbarx
Callum.
Something like this?
...

Well, does it work? Yes indeed, if so. On another note, I would, except for the quickest of down and dirty tests, change the name of all objects to something that LC does not see as a conflict. graphic 'tLine", for example.

Craig

EDIT.

And after you have this working well, we really must rethink the overall structure. I hate seeing card references as object references.

Re: Button script

Posted: Fri Nov 15, 2013 9:10 pm
by calmrr3
Not at the moment I can't think why though. Does "Line1to2" need to be a part of the same group as the dots or does this not matter?