How to change order of fields in a group?

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
mrmopo
Posts: 3
Joined: Thu Feb 29, 2024 5:03 pm

How to change order of fields in a group?

Post by mrmopo » Thu Feb 29, 2024 5:15 pm

Ive got a group of 30 fields set up like this
x x x x x
x x x x x
x x x x x
x x x x x
x x x x x
x x x x x

They are labelled 1 to 30 and a lot have some unique code so I’d rather not remake them all, but when I iterate through them via the group it goes backwards starts bottom left and goes to top right :( :(
How do I flip the order that they are iterated through
I don’t mind making a new group if I need to
This is the code I use to iterate through the fields

Code: Select all

 put the num of flds of grp "MainGroup" into num fields
repeat with i = 1 to num_fields
    put empty into fld 1 of grp "MainGroup"
    set the backgroundColor of fld i of grp "MainGroupp' to ##b5b565"
    set the lockText of fld i of grp "MainGroup" to true
And so on
I’m writing this on a phone so there may be some weird formatting so apologies

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to change order of fields in a group?

Post by Klaus » Thu Feb 29, 2024 5:40 pm

Hi mrmopo,
They are labelled 1 to 30...
Do you mean they are named 1, 2,...30?
If yes, DON'T!

Use a least one character as the first character of the name, maybe f1, f2 etc.
For LC -> field "1" is the same as -> the first field on the card -> field 1

I am not sure i understand your question/problem!?
Maybe you mean:

Code: Select all

...
put the num of flds of grp "MainGroup" into num_fields
repeat with i = num_fields down to 1
    put empty into fld i of grp "MainGroup"
    set the backgroundColor of fld i of grp "MainGroupp" to ##b5b565"
...
?

Best

Klaus

P.S.
A personal note, a littel "Hello" or something would not have hurt for the very first posting.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 5:50 pm

Hi.

Welcome to the forum.

When you do this sort of thing, you really want, at the beginning, to make some property of each field commensurate with your requirements. Otherwise you are limited to letting LC navigate according to the only information it has, which is the layer number of each field. That would be set as you created those fields. LC will simply follow that schema, as you already see.

The group is not pertinent.

So yes, you could re-order all your fields. But I would recommend naming your fields, something like "myField1, myField2..." In this way you could:

Code: Select all

repeat with i = 1 to the number of fields
    put empty into fld "myField" & i
    set the backgroundColor of fld "myField" & i to ##b5b565"
    set the lockText of fld "myField" & i to true
Now this is also a task, but at least it takes the "working" property away from LC, and gives it to you.
Last edited by dunbarx on Thu Feb 29, 2024 6:46 pm, edited 2 times in total.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to change order of fields in a group?

Post by Klaus » Thu Feb 29, 2024 6:00 pm

dunbarx wrote:
Thu Feb 29, 2024 5:50 pm
...
But I would recommend naming your fields, something like "myField1, myField2..."
You can also do this by script:

Code: Select all

...
put the num of flds of grp "MainGroup" into num_fields
repeat with i = 1 to num_fields
  set the name of fld i of grp "MainGroup" to ("field" & i)
  ...
Late you can iterate throiugh all fields like this:

Code: Select all

...
put the num of flds of grp "MainGroup" into num_fields
repeat with i = 1 to num_fields
## or:
## repeat with i = num_fields down to 1
  put empty into fld ("field" & i) of grp "MainGroup"
  set the backgroundColor of fld ("field" & i) of grp "MainGroup" to "##b5b565"
  ...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 6:12 pm

You can do this easily in a button:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of flds
      put "myField" & (31 - the layer of fld y) into newName
      set the  name of fld y  to newname
   end repeat
end mouseUp
This assumes there are only those 30 fields on the card.

Craig

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to change order of fields in a group?

Post by stam » Thu Feb 29, 2024 6:25 pm

Can I check with @mrmopo - the 30 fields in a matrix... are you sure this shouldn't be a tableField or datagrid?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 6:30 pm

I see Klaus has posted something similar, but we do not do exactly the same thing. He is making your handler work. I am changing the properties of your fields. I bet that this will come in handy pretty soon.

The lesson here, and this takes experience, to learn a few tricks so that you can more easily modify your stack down the road. One is as Klaus mentioned, assuming you actually did that, NEVER name your controls with a simple integer. LC uses integers for its own purposes, and you do not want to get into that space. My handler uses integers in renaming those fields, but also does not use them alone. Those values may be easily parsed later on in useful ways.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 6:44 pm

I hope you are having as much fun not working as I am.

Here is a stack that selects a series of fields based on either layer (the order you bought into when you created your fields) and name. Keep naming conventions in mind as you build stuff.

Craig
LayerLesson.livecode.zip
(1.34 KiB) Downloaded 15 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 6:47 pm

Stam.

What is " @mrmopo "??

Craig

stam
Posts: 2686
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: How to change order of fields in a group?

Post by stam » Thu Feb 29, 2024 7:05 pm

dunbarx wrote:
Thu Feb 29, 2024 6:47 pm
Stam.

What is " @mrmopo "??

Craig
Seriously dude lol - @ signifies the word following is a handle/user. This is used on almost all collaborative sites/email systems like Outlook/social media. It is not at all a rarity of any kind. mrpopo is the OP (the original post/poster).

Hence @mrpopo means I'm addressing him/her. Or simply put the message is directed at (@) mrpopo (the OP).
I really didn't think I needed to clarify this of all things lol ;)


Not sure why you felt this was the curiosity and obviously didn't think the content of the question was worth addressing however.
A polyList, polyGrid, datagrid or even the lowly tableField can produce a matrix which makes the totality of the data easier to manage, is easily resizeable etc.

Just wanted to check this wasn't a better fit for the OP's needs instead of going down a rabbit hole of 30+ fields.

mrmopo
Posts: 3
Joined: Thu Feb 29, 2024 5:03 pm

Re: How to change order of fields in a group?

Post by mrmopo » Thu Feb 29, 2024 7:28 pm

stam wrote:
Thu Feb 29, 2024 6:25 pm
Can I check with @mrmopo - the 30 fields in a matrix... are you sure this shouldn't be a tableField or datagrid?
no, but i probably should of used a tableField now that you mention it lol

mrmopo
Posts: 3
Joined: Thu Feb 29, 2024 5:03 pm

Re: How to change order of fields in a group?

Post by mrmopo » Thu Feb 29, 2024 8:01 pm

Klaus wrote:
Thu Feb 29, 2024 5:40 pm

Code: Select all

...
put the num of flds of grp "MainGroup" into num_fields
repeat with i = num_fields down to 1
    put empty into fld i of grp "MainGroup"
    set the backgroundColor of fld i of grp "MainGroupp" to ##b5b565"
...
I thought about this but I was trying to avoid it because I have other parts later on like this:

Code: Select all

repeat with i = 1 to 5
      put colourArr[current_line][i] into temp
      if colourArr[current_line][i] = 0 then
         set the backgroundColor of fld ((current_line*5)-(5-i)) of grp "MainGroup" to "#b5b5b5"
      else if colourArr[current_line][i] = 1 then
         set the backgroundColor of fld ((current_line*5)-(5-i)) of grp "MainGroup" to "#faf32f"
      else
         set the backgroundColor of fld ((current_line*5)-(5-i)) of grp "MainGroup" to "#49e82a"
      end if
   end repeat
where i am doing some stuff with the group based on the "line" and "row" of my fields that i am on and i was praying there was a way where i could be lazy and not change it all lol

But I think dunbarx's soloution fits best for me and I will just implement it any time I would have been using the group
dunbarx wrote:
Thu Feb 29, 2024 5:50 pm

Code: Select all

repeat with i = 1 to the number of fields
    put empty into fld "myField" & i
    set the backgroundColor of fld "myField" & i to ##b5b565"
    set the lockText of fld "myField" & i to true
Now this is also a task, but at least it takes the "working" property away from LC, and gives it to you.
(dunbarx's ^)

Klaus wrote:
Thu Feb 29, 2024 5:40 pm
A personal note, a littel "Hello" or something would not have hurt for the very first posting.
sorry about this, I had thought it might be too formal to do an introduction but I probably should have at least said hello
thanks for the help guys

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: How to change order of fields in a group?

Post by Klaus » Thu Feb 29, 2024 8:10 pm

It is NEVER too formal to do an introduction! 8)

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: How to change order of fields in a group?

Post by dunbarx » Thu Feb 29, 2024 10:12 pm

Stam.

I missed the "name" of the OP.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”