PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Need help with an FAQ

Hi,

I am starting work on an FAQ on the PPL official's web site and I would like you guys to contribute with tips and tricks you have learnt from PPL over the last few months.

I plan on having different sections like:

Arrays
List
Structures
Matrix
GameAPI
...

Please post your question and answer here, I will add them to the site.

You can take a look at the early work I did already:

http://ppl.arwen.com/FAQ/
bmanske · 15 Dec 2004, 20:06 UTC — How to make a list of structures.
To use a structure first define the structure...
Code:

#define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}

A single instance of the structure is declared...
Code:

struct(ControlInfo$, ControlStruct);

then filled with data...
Code:

Fill(ControlInfo$, "Form", "FORM", 0, "WS_TABSTOP|WS_VISIBLE");

Now, if you want a list of these structures, the declaration of the struct must happen for each element in the list. Here is an example...
Code:

#define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}

proc InitCtlInfo
global(ControlInfo$);
list(ControlInfo$);

add(ControlInfo$);
struct(ControlInfo$, ControlStruct);
Fill(ControlInfo$, "Form", "FORM", 0, "WS_TABSTOP|WS_VISIBLE");

add(ControlInfo$);
struct(ControlInfo$, ControlStruct);
Fill(ControlInfo$, "Button", "BUTTON", 1, "WS_TABSTOP|WS_VISIBLE");

add(ControlInfo$);
struct(ControlInfo$, ControlStruct);
Fill(ControlInfo$, "CheckBox", "BUTTON", 2, "WS_TABSTOP|WS_VISIBLE");
end;

proc main
InitCtlInfo;
goto(ControlInfo$, 0);
ShowMessage(@ControlInfo.CtlType$, ",", ControlInfo.CtlIndex$ ",",
Count(ControlInfo$));
end;

In order to improve readability and take a few lines out of the code I chose to use a small helper procedure.
Code:

#define ControlStruct {"CtlType", "CtlClass", "CtlIndex", "CtlDefStyle"}

proc FillCtlInfo(a1$, a2$, a3$, a4$)
add(ControlInfo$);
struct(ControlInfo$, ControlStruct);
ControlInfo.CtlType$ = a1$;
ControlInfo.CtlClass$ = a2$;
ControlInfo.CtlIndex$ = a3$;
ControlInfo.CtlDefStyle$ = a4$;
end;

proc InitCtlInfo
list(ControlInfo$);
struct(ControlInfo$, ControlStruct);
FillCtlInfo("Form", "FORM", 0, "WS_VISIBLE|WS_BORDER");
FillCtlInfo("Button", "BUTTON", 1, "WS_VISIBLE|WS_TABSTOP");
FillCtlInfo("CheckBox", "BUTTON", 2, "WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX");
end;

proc main
InitCtlInfo;
goto(ControlInfo$, 0);
ShowMessage(@ControlInfo.CtlType$, ",", ControlInfo.CtlIndex$ ",",
Count(ControlInfo$));
end;

The thing to remember here is that an element in a list always has to be type cast as a structure after it is created.

B.