|
Getting started with SuperCard can be a little harder than, say, getting started with Microsoft Word. This is because of what SuperCard can do, rather than any failing on the part of the developers. SuperCard's manuals are widely regarded as examples of some of the best documentation around, but new users can still feel a little lost - the manuals are superb for using SuperCard, but they can feel a little light on getting people started in the first place. There is a tutorial, and parts of the User Guide help people understand the general syntax of the language, but there needs to be a little more in the way of 'absolute beginner's guides'.
What you need are some reasonably simple examples to dissect, and some simple tasks to attempt and customise. Here's a very simple example to get you started. If this helps I'll try to whip up a few more covering different areas of SuperCard use.
Briefly: A SuperCard project consists of one or more windows. Each window will contain one or more cards. To keep things simple for now, stick to using just one window. And at first, stick to using just one card until you have a specific need for more.
Right? Oh, sorry - didn't mean to bore anyone ;-)
I'm going to presume you're using the Project Editor. There are reasons why you might want to use SuperEdit or one of the alternative editors, but that can wait.
Fire up SuperCard. Make a new project. You'll be asked whether to open it in 'design' mode or 'run' mode. Choose 'design', as this is where the construction tools are. You'll automatically be given a single window with a single card, 320 pixels wide by 240 pixels high unless you've changed the defaults in the preferences.
You should have two palettes already open; the Tool Palette and the Property Inspector. If either isn't open fix this via the Tools menu.
Right. Now you have a naked project with no items on your card. Choose the Rounded Rectangle Button tool from the Tools Palette (second down in the second row) and drag a button out somewhere on the card. You should be asked to name it as soon as you finish creating it. This is standard behaviour unless you change this in the preferences.
For now, just hit "OK" without naming it. Now look in the Property Inspector palette. With the new button still selected you should see its details in this palette window:
Name: [empty] No: 1 ID: 100 Style: [RoundRect]
Along with some tabs and checkboxes.
You can name it from here. (So it isn't vital to name things as they are created. Just sometimes helpful.) You can refer to this button in a number of ways, which is useful to remember later on when you are writing scripts. You can say:
either card button "button name"
or card button 1
or card button ID 100
Of course, you can't actually refer to THIS button by name, as it doesn't have one yet. To name it, just click in the Name field in the Property Inspector palette and type. For this exercise type the number "1", and then press Return or Enter. Yes, I know it is also card button 1 (that is, number 1), but this is different.
As long as the "showName" option in the Property Inspector is checked the name will be shown centered in the button. (You can actually change the alignment to left or right if you like, although this usually looks odd.)
Now we will put a reasonably simple script into this button. We will get the button to change its name when it is clicked. It is currently called "1", so we will ask it to change the name to "2". The simplest script for this would be:
on mouseUp
set the name of me to "2"
end mouseUp
You can test this by 'running' the project. Type command-R, choose Run Project from the Go menu, or click the Run Project button in the Project Editor's button bar. Now click the button you just made. It should change its name from "1" to "2".
To get back to your editing environment either click the Return to Editor button in the little floating palette or simply type command-Tab.
The problem with this script is that it is effectively a single-shot one. Once the name is changed there's no point in clicking it again. (Even though the script still operates, it just blindly changes the name from "2" to "2".)
To make a more flexible script, we'll tell the button to change its name to whatever its name is plus 1. Now, that previous sentence isn't real script, but the logic and even the structure is surprisingly close to what we need.
The "mouseUp" handler is the identifying wrapper for the lump of script which tells SuperCard what action is the script trigger. This is already typed for you in every button item, so when you open the button's Script Editor window (select the button and type command-E or choose Edit Script from the Tools menu) all you need to do is type the line of script inbetween the "on mouseUp" and "end mouseUp" lines.
Remember our pseudo script? Like I said, it is pretty close to the final article:
CONCEPT: change its name to whatever its name is plus 1
SCRIPT: set the name of me to the short name of me + 1
So the final script is:
on mouseUp
set the name of me to the short name of me + 1
end mouseUp
We can simply refer to the button as "me" because the script is operating from within the button itself. The reason we have to say "the short name of me" rather than "the name of me" is because the 'name' of an item includes the decription of the object type, while the 'short name' is just the name itself. (When the script attempts to add 1 to whatever the name is, it has to have a simple number to use, not a string of numbers and letters.) For example:
the name of me = card button "1"
the short name of me = 1
The button's name will now keep increasing by 1 every time it is clicked. To make it reset itself when it reaches 10 you'll have to stick in a simple line of script to check the button's name and change it to "1" if it has reached 10. So: if the button's name is "10" then change the name to "1".
CONCEPT: if the button's name is "10" then change the name of the button to "1"
SCRIPT: if the short name of me is "10" then set the name of me to "1"
on mouseUp
set the name of me to the short name of me + 1
if the short name of me is "10" then set the name of me to "1"
end mouseUp
|