1

I have a hopefully easy to solve problem with my program. My program works 99% (haven't tried to break it yet haha) and I'm on to formatting for scaling to multiple platforms etc. There is one small part of my program that is particularly hard to position, however, as I have multiple objects which are not individually always visible. I wrote some example pseudocode for what I want to do, but I was unable to find a lot of helpful syntax to help me fulfill the pseudocode. The pseudocode is as follows (apologies because my pseudocode is probably not formally correct):

FOR each object
    IF object required then
        Add object to group
    ELSE
        Hide object
    END IF
END FOR
CENTER group

After this I should have a completed minimum viable product for my program, so help is much appreciated. Cheers!

Mark
  • 2,380
  • 11
  • 29
  • 49
notHalfBad
  • 213
  • 2
  • 9

3 Answers3

0

Use the showcommand to show objects and the hidecommand to hide objects. Don't forget to refer to your group: control x of group yor control x of meif the script is in the group itself.

examples:

show field 1 of group "Purple"
hide button "Click Me" of me
Mark
  • 2,380
  • 11
  • 29
  • 49
0

Here's some of the code for your pseudocode. (Note sure I'm capturing the nuances of what you're trying to do.)

repeat with x = 1 to the number of buttons in group "foo"
   put the long id of button x of group "foo" into tBtn
   if tObjectIsNeeded then
      show tBtn
   else
      hide tBtn
   end if
end repeat
# this centers the group horizontally and vertically
set the loc of group "foo" to the loc of this card

You can add an object to a group using the copy command:

copy button "bar" into group "foo"

You can use the delete command to delete a control from a card:

delete button "bar" from group "foo"

If you only want to align the group horizontally, modify its location property. The location property is a comma-separated list of two integers, the first one giving the number of pixels from the left edge of the card, and the second one giving the number of pixels from the top of the card. It would look something like this:

set the itemDelimiter to comma # comma is default, so this line might not be needed
put item 1 of the loc of this card into tXloc
put item 2 of the loc of group "foo" into tYloc
set the loc of group "foo" to tXloc,tYloc
Devin
  • 593
  • 1
  • 3
  • 8
  • I forgot to mention that if the object is not needed, I want to make sure the object is not in the group. Is there syntax for removing something from a group? Also I only want to centre the group along the vertical axis, as the horizontal axis will remain the same, or at least proportional to the scale of other elements. – notHalfBad May 25 '16 at 22:56
0

A group's rectangle can be a different size than the controls it contains, so I wouldn't bother adding or removing controls, I'd just resize the group itself to fit the visible ones. Then just center the group as needed.

If this is part of the hangman game you're developing, the left of the first visible field will become the left edge of the group and the right of the last visible field will be the right side of the group. The top and bottom remain the same.

Try this, using the correct field names for "firstfield" and "lastfield":

  put the rect of grp "foo" into tRect
  put the left of field "firstfield" into item 1 of tRect
  put the right of field "lastField" into item 3 of tRect
  set the rect of grp "foo" to tRect -- resizes group to fit visible controls
  -- now center the group along the horizontal axis:
  set the loc of grp "foo" to (item 1 of the loc of this cd),item 2 of the loc of grp "foo"
Jacque
  • 416
  • 2
  • 7