How to change card order of cards (numbers)?

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

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

How to change card order of cards (numbers)?

Post by samjith » Wed Jun 01, 2016 6:02 am

Hi,

hoping all gurus are fine. but i am not good, because of headache, with a topic.

I am attaching a zip file, which you can understand what i wan't to do.
but it doesn't contains code, because this is just an example of what i need.

I have total 15 cards, (each cards contains different values on their custom property)
A,B,C and D are my main cards and each have many corresponding child cards.

A(1-3)
B(4-5)
C(6-10)
D(11-15)

if i type "A--C" and enter in field "Field" then the card order changes to

A(1-5)
B(6-7)
C(8-10)
D(11=15)

I tried this for 2 days. but failed to get the answer.

Thanks
-/-
Samjith
Attachments
test.zip
(1.05 KiB) Downloaded 290 times

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

Re: How to change card order of cards (numbers)?

Post by Klaus » Wed Jun 01, 2016 6:28 pm

NONE of your cards has a name or custom property!?
No idea what you are trying to do...

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

Re: How to change card order of cards (numbers)?

Post by dunbarx » Wed Jun 01, 2016 9:44 pm

Hi.

I am not in v.8 yet. Can you restate your problem? I cannot understand the issue at all, or what your original post means.

Craig Newman

shalu
Posts: 72
Joined: Fri Mar 20, 2015 1:05 pm

Interchange card and sub-card

Post by shalu » Thu Jun 02, 2016 9:42 am

Hi All

I have three main cards and each main card three or more sub card, I have an textfield for passing the input, when I enter the input as 1to3 in text field then interchange the first main card and sub card by third main card and sub card. is it possible :(
--
Thanks
Shalu S

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

Re: How to change card order of cards (numbers)?

Post by Klaus » Thu Jun 02, 2016 10:23 am

Hi Shalu,

I merged your two topics, please do not simply open a new thread
if noone seems to understand your previous one! 8)

I still do not have any idea what you are after, and there are no
SUB cards (like a SUB stack), just cards!


Best

Klaus

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

Re: How to change card order of cards (numbers)?

Post by dunbarx » Thu Jun 02, 2016 1:58 pm

As Klaus said, "What are sub-cards?"

Do you mean simply that a certain card is related in some way to three other cards? So if you enter "1to3" onto card 1, card 3 appears? But then how could more than one "other" card appear?

Are we sure we know what is meant by "card"?

Craig

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: How to change card order of cards (numbers)?

Post by Newbie4 » Thu Jun 02, 2016 3:23 pm

Before we can help you work out the code, we need to understand what you would like to do. One of the problems is the vocabulary - LiveCode does not have a concept of subcards but we can work that out later. Using your terms, is this what you are trying to do?

See if this is correct:

Your cards are arranged like this:

A - has 3 subcards
B - has 2 subcards
C has 5 subcards

you want to be able to swap subcards as a group from one letter to another

A..C would swap subcards so you would get this:

A - now has C's subcards
B - still has its own
C - has A's subcards

Is that a correct understanding of what you want to do?
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to change card order of cards (numbers)?

Post by samjith » Fri Jun 03, 2016 1:29 pm

Hi Shalu,

I merged your two topics, please do not simply open a new thread
if noone seems to understand your previous one! 8)

I still do not have any idea what you are after, and there are no
SUB cards (like a SUB stack), just cards!


Best

Klaus
Firstly, i want to say that, i am not shalu, he is my colleague. but we are doing the same project.
See if this is correct:

Your cards are arranged like this:

A - has 3 subcards
B - has 2 subcards
C has 5 subcards

you want to be able to swap subcards as a group from one letter to another

A..C would swap subcards so you would get this:

A - now has C's subcards
B - still has its own
C - has A's subcards

Is that a correct understanding of what you want to do?
Yes, that is what i meant.
I know LC have no sub cards, but i want to make them sub cards (just assumption),
because i need to move the cards to

A(1-3)--here 1 is A and 2,3 are child of A
B(4-5)-- 4 is B and 5 is child of B
C(6-10) 6 is C and 7,8,9,10 are child of C
D(11-15) 11 is D and 12,13,14,15 are child of D

Why i made as child because, i need to move cards with some cards

if i type "Swap A--C" and enter in field "Field" then the card order changes to

A(1-5)
B(6-7)
C(8-10)
D(11=15)

This is what i tried so far but failed. I don't know whether you can understand what i tried

Code: Select all

if char 1 to 4 of command is "swap" and the char 5 to -1 of command is not empty then
      if charToNum(the char 5 of command) <  charToNum(the char 6 of command) then ---So no problem with swapAC/swapCA
         put char 5 of command into First_Part_to_Swap --A
         put char 6 of command into Second_Part_to_Swap--C
      else
         put char 6 of command into First_Part_to_Swap--C
         put char 5 of command into Second_Part_to_Swap--A
      end if 

      put 0 into First_Card_counter
      put 0 into Second_Card_counter
      repeat with i =1 to the number of cards 
         if the My_Part_name of card i is First_Part_to_Swap and the is_part of the card i is true then--My_Part_name contains A/B/C etc--is_part means my main card
            put the number of card i into First_Card_Numb
            put the short name of card i into temp1
            put the Finish_Row of card i into temp1_finish
            put the Start_Row of card i into temp1_start
            put the Horizontal_skip of card i into temp1_hori
            put the Vertical_skip of card i into temp1_ver
            put the My_Part_name of card i into temp1_part_alpha
            add 1 to First_Card_counter
         else if the Part_name of card i is temp1 and the is_Label of card i is true then--is_Label means my sub card 
            add 1 to First_Card_counter
         end if ---------This is for A
         
         if the My_Part_name of card i is Second_Part_to_Swap and the is_part of the card i is true then 
            put the number of card i into Second_Card_Num
            put the short name of card i into temp2
            put the Finish_Row of card i into temp2_finish
            put the Start_Row of card i into temp2_start
            put the Horizontal_skip of card i into temp2_hori
            put the Vertical_skip of card i into temp2_ver
            put the My_Part_name of card i into temp2_part_alpha
            add 1 to Second_Card_counter
         else if the Part_name of card i is temp2 and the is_Label of card i is true then
            add 1 to Second_Card_counter
         end if --This is for C
      end repeat
      
repeat with i = Second_Card_Num to (Second_Card_Num  + Second_Card_counter-1)
         if the Part_name of card i is temp2 and the is_part of card i is true then
            set the number of card i to First_Card_Numb
            set the Finish_Row of card First_Card_Numb  to temp1_finish
            set the Start_Row of card First_Card_Numb  to temp1_start
            set the Horizontal_skip of card First_Card_Numb  to temp1_hori
            set the Vertical_skip of card First_Card_Numb  to temp1_ver
            set the My_Part_name of card First_Card_Numb  to temp1_part_alpha
            put 0 into tmp
         else if the Part_name of card i is temp2 and the is_Label of card i is true then
            add 1 to tmp
            set the number of card i to First_Card_Numb  + tmp
         end if
      end repeat
      
      
      repeat with i = (First_Card_Numb+ Second_Card_counter)  to First_Card_Numb + Second_Card_counter + First_Card_counter -1
         if the Part_name of card i is temp1 and the is_part of card i is true then
            set the number of card i to  y--Second_Card_Num 
            set the Finish_Row of card y to temp2_finish
            set the Start_Row of card y to temp2_start
            set the Horizontal_skip of card y to temp2_hori
            set the Vertical_skip of card y to temp2_ver
            set the My_Part_name of card y  to temp2_part_alpha
            put 0 into tmp
         else if the Part_name of card i is temp1 and the is_Label of card i is true then
            add 1 to tmp
            set the number of card i to y + tmp
         end if
      end repeat
   end if 

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

Re: How to change card order of cards (numbers)?

Post by Klaus » Fri Jun 03, 2016 1:57 pm

Hi Samjith,

sorry, for naming you Shalu, but it would be good if you could communicate a bit
so we do not have different threads for the same problem!

I think your script is unneccessarily complicated, since I still do not have any idea about the logics behind your wish!?

Hint:
A clever naming scheme often make things easier to handle.
So can you please NAME your cards like:
A_1
A_2
A_3
B_1
B_2
etc.

And then explain again what you are trying to do with these NAMES in a little example?


Best

Klaus

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to change card order of cards (numbers)?

Post by samjith » Fri Jun 03, 2016 2:09 pm

A_1
A_2
A_3
B_1
B_2
C_1
C_2
C_3
C_4
C_5
D_1
D_2
D_3
D_4
D_5

Are in order 1 to 15, when i type "swapAC" in field, i want to see them look like this

C_1
C_2
C_3
C_4
C_5
B_1
B_2
A_1
A_2
A_3
D_1
D_2
D_3
D_4
D_5

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

Re: How to change card order of cards (numbers)?

Post by Klaus » Fri Jun 03, 2016 2:11 pm

AHA! :D

OK, thanks, NOW I can and will think about this.

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: How to change card order of cards (numbers)?

Post by Newbie4 » Fri Jun 03, 2016 2:18 pm

If you name your cards as Klaus suggested, your task becomes easier.
e.g.
A-1
A-2
A-3
B-4
B-5
C-6
C-7
C-8
etc.

You would set the itemDelimiter to the separator (either _ or -) and treat each name as having 2 items - the letter (A,B,C) and the number.

When you go to swap, you loop through all the cards and change the first item of each line (the letter). Then you sort the lines, then loop through all of them changing the second items (the numbers) to be consecutively numbered.

Does that make sense? Do you need help with the code?

e.g.
to swap A with C:

1. move the children (subcards) from one to the other:
loop through every card -
if first item = "A" then change to a "C"
if first item = "C" then change to a "A"

2. Sort them so they are in the new order

3. Now renumber them to be consecutive
loop through every card - (put 1 into i)
change item 2 to i
increment i (add 1 to i)

Is this what you had in mind?

note: in your original example, the cards were numbered consecutively. The code above is for that scenario.

if you want them numbered differently, (in your last example) then you do not need to do the sort and renumbering steps above (2 and 3)
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

samjith
Posts: 85
Joined: Tue Mar 31, 2015 10:09 am

Re: How to change card order of cards (numbers)?

Post by samjith » Mon Jun 06, 2016 4:13 am

Does that make sense? Do you need help with the code?

Sorry, I am very much confused. Could you help me with the code?

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: How to change card order of cards (numbers)?

Post by [-hh] » Mon Jun 06, 2016 10:59 am

## Preparation (do ONCE)
  • Name each card, don't touch the name again (read it only)
    => names A_1 ... C_8 and more of that type
  • name the one card of your actions with "TOP"
  • make (if not already there) on card "TOP"
    => a field "Swap"
    => a field "OUT"
    => a field "fullList" (containing all used chars = ABCD ...)
    => a button "Action" with the following script

Code: Select all

## Actions
-- newSort "ABCD" --> resets the sort
-- newSort "ACBD" --> swaps BC
on newSort sortCode
  set itemdel to "_"
  sort cards by offset(item 1 of the short name of this card,sortCode)
  set itemdel to comma
end newSort

-- swapCards is based by default on "ABCD"
-- if you wish to do a repeated swap then
-- keep track of fullList (by fld "fullList")
on swapCards
  lock screen; lock messages
  put numTochar(0) into c0
  -- put fld "fullList" into fullList --> for repeated swaps
  put "ABCD" into fullList --> swap based on natural order
  put upper(char -2 of fld "swap") into c1
  put upper(char -1 of fld "swap") into c2
  if c1 is in fullList and c2 is in fullList then
    replace c1 with c0 in fullList
    replace c2 with c1 in fullList
    replace c0 with c2 in fullList
    -- put fullList into fld "fullList"
    newSort fullList
    go card "TOP"
    put fullList & cr & getOrder() into fld "OUT"
  else
    answer "Error: Not all SwapChars are in " & \
          quote & fullList &quote & "..."
  end if
  unlock screen; unlock messages
end swapCards

on mouseUp
  swapCards 
end mouseUp

-- for checking the new sort order in development
function getOrder
  repeat with i=1 to the num of cds
    put cr & the short name of card i after s
  end repeat
  return char 2 to -1 of s
end getOrder
Of course you can get with that code a full new order at once by

Code: Select all

on mouseUp
  lock screen; lock messages
  put "CBDA" into newOrder -- or read it from a field
  newSort newOrder
  go card "TOP"
  put newOrder & cr & getOrder() into fld "OUT"
  unlock screen; unlock messages
end mouseUp
shiftLock happens

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 332
Joined: Sun Apr 15, 2012 1:17 am
Contact:

Re: How to change card order of cards (numbers)?

Post by Newbie4 » Mon Jun 06, 2016 2:14 pm

This is the base code for changing the name of the cards. This is as simple as it gets
You will have to modify it to handle your card names and your input for the letters to swap. I hard-coded the "A" and "C" but you should be able to make it more generic (i.e. get the letters from a field, put them into variables) and use those variables in the "if" statements. I assume that you know enough LiveCode to do that.

(this assumes the cards are named A-1 , A-2 , A-3 , B-1 ,etc)

Code: Select all

on mouseUp
   repeat with n=1 to the number of cards of this stack
      set itemDelimiter to " "
      put the short name of card n into theName
      if char 1 of theName = "A" then
         put "C" into char 1 of theName
      else
         if char 1 of theName = "C" then
            put "A" into char 1 of theName
         end if
      end if
      set the name of card n to theName
   end repeat
Then you can sort the cards to get them back in alphabetical order.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Post Reply