Fourth World Logo Fourth World Media Corporation
  Embassy Services Products Resources   About Fourth World Contact  

IncWell Logo

SuperCard FAQ

4W Logo

How can I create a polygon from a script?

SuperCard's draw polygon tool is one of the very few tools which require user interaction (along with the draw curve tool), and therefore cannot be used to create a polygon from a script alone. But it can be done, and here's how:

Remember that many types of SuperCard draw graphic objects can be converted to other types by changing the "style" of the object. Remember also that you can change the shape of a polygon by setting its "points" property, which is a comma-delimited list of coordinates in which every odd-number coordinate represents the X-axis value for a given point, and every odd number the Y-axis coordinate.

With this in mind, below is a handler which will accept a list of points and create a new polygon object using those points:

on CreatePolygon tPointsList
-- Check points list to make sure it is valid:
if the number of items of tPointsList mod 2 <> 0 then
return "Error: Invalid points passed to CreatePolygon."
end if

lock screen

-- First, we make a draw rectangle object:
choose draw rectangle tool
drag from 10,10 to 100,100
if the editBg is true the
put the long ID of last bg grc into tNuGraphic
else put the long ID of last grc into tNuGraphic

-- Now we convert this object to a polygon:
set the style of tNuGraphic to polygon
-- New we set the points of this object to the
-- points passed into this handler:
set the points of tNuGraphic to tPointsList

end CreatePolygon