How to array objects? - Solved
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How to array objects? - Solved
global Resistor_H
on mouseDown pButtonNumber
put 1 into x
set loc of grp Resistor_H[x] to 200,200
end mouseDown
The user needs to be able to add groups that are composed of unique names for the items within the group, so that script can control each new user added groups properly.
Thanks,
David
on mouseDown pButtonNumber
put 1 into x
set loc of grp Resistor_H[x] to 200,200
end mouseDown
The user needs to be able to add groups that are composed of unique names for the items within the group, so that script can control each new user added groups properly.
Thanks,
David
Last edited by DR White on Thu Jun 06, 2019 10:47 am, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to dimension objects?
Hi.
In any case, why do you use an array? There is no reason not to, particularly, but you do not need to. For example, if you had two groups, "yourGroup1" and "yourGroup2", then in a button script somewhere:
I suspect I am missing your point, though, since I do not understand the title of the thread.
Craig
The user needs to be able to add new groups of controls, or new controls within a group? Are you saying that the names of the child controls somehow relate to the name of the group? Let us know. Or me, at least.The user needs to be able to add groups that are composed of unique names for the items within the group
In any case, why do you use an array? There is no reason not to, particularly, but you do not need to. For example, if you had two groups, "yourGroup1" and "yourGroup2", then in a button script somewhere:
Code: Select all
on mouseUp
repeat with y = 1 to 2
set the loc of grp ("yourGroup" & y) to "100," & random(300)
end repeat
end mouseUp
Craig
Re: How to dimension objects?
Craig,
No, you did not miss my point.
I am using the method that you had in your sample code (which I always appreciate "sample code").
I did not know if there was an easier way using a group with "[x]" in a dimension format.
I will continue to use the same format that you showed in your code.
Thanks,
David
No, you did not miss my point.
I am using the method that you had in your sample code (which I always appreciate "sample code").
I did not know if there was an easier way using a group with "[x]" in a dimension format.
I will continue to use the same format that you showed in your code.
Thanks,
David
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to dimension objects?
OK.
Still not sure what "dimension" means, but maybe you do, and that is all that matters.
Craig
Still not sure what "dimension" means, but maybe you do, and that is all that matters.
Craig
Re: How to dimension objects?
When I use the word "dimension", a better word might be array.
example:
David [2,2}
David [1,1} = Bill
David [1,2} = John
David [2,1} = Sally
David [2,2} = Susan
So my real question was "Can I reference groups in an a array format?"
ex. group David[1,2]
As you said, its not a big deal.
Thanks
example:
David [2,2}
David [1,1} = Bill
David [1,2} = John
David [2,1} = Sally
David [2,2} = Susan
So my real question was "Can I reference groups in an a array format?"
ex. group David[1,2]
As you said, its not a big deal.
Thanks
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to dimension objects?
Well, sure. You can use an array variable instead of an "ordinary" variable. You already have your named groups. You just change the syntax slightly:
In the "ordinary" method in the post above, LC builds the name reference on the fly. In the "array" method, this does not work:
Because LC resolves the term "yourGroup[y]" to "2", and you are then trying to work with "group 2" instead of group "yourGroup2".
You should play around with this sort of thing, though.
Craig
Code: Select all
on mouseUp
repeat with y = 1 to 2
put y into yourGroup[y]
set the loc of grp yourGroup[y] to "100," & random(300)
end repeat
end mouseUp
Code: Select all
on mouseUp
repeat with y = 1 to 2
set the loc of grp yourGroup[y] to "100," & random(300)
end repeat
end mouseUp
You should play around with this sort of thing, though.
Craig
Last edited by dunbarx on Thu Jun 06, 2019 3:57 pm, edited 3 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to dimension objects?
Just so you know, you would have to:
Array variable are powerful and flexible. But they are not quite as accessible and direct as ordinary variable, and, well, not as simple.
Craig
Code: Select all
on mouseUp
repeat with y = 1 to 2
set the loc of grp ("yourGroup" & yourGroup[y]) to "100," & random(300)
end repeat
end mouseUp
Craig
Re: How to dimension objects?
Thanks,
Craig
Craig