mirror of https://github.com/marrub--/zscript-doc
somehow missed these files
parent
8081cd640b
commit
37e4f2a68b
|
@ -38,7 +38,7 @@ A class is formed with the syntax:
|
|||
```
|
||||
class Identifier $[ : Base-class]$ $[Class-flags...]$
|
||||
{
|
||||
$[Class-content...]$
|
||||
$[Class-content...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -108,14 +108,14 @@ Basic class definition with a member variable and member function.
|
|||
```
|
||||
class BasicClass
|
||||
{
|
||||
// "m_Thing" is attached to any "instance" of BasicClass.
|
||||
int m_Thing;
|
||||
// "m_Thing" is attached to any "instance" of BasicClass.
|
||||
int m_Thing;
|
||||
|
||||
// Changes "m_Thing" to 500 on an instance of BasicClass.
|
||||
void ChangeThing()
|
||||
{
|
||||
m_Thing = 500;
|
||||
}
|
||||
// Changes "m_Thing" to 500 on an instance of BasicClass.
|
||||
void ChangeThing()
|
||||
{
|
||||
m_Thing = 500;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -186,21 +186,21 @@ A class with some properties.
|
|||
```
|
||||
class MyCoolActor : Actor
|
||||
{
|
||||
// You can set defined properties in a "default" block like in DECORATE.
|
||||
// This will also be available in DECORATE code that inherits your class!
|
||||
default
|
||||
{
|
||||
MyCoolActor.MyCoolMember 5000;
|
||||
MyCoolActor.MyCoolMemberList 501, 502;
|
||||
}
|
||||
// You can set defined properties in a "default" block like in DECORATE.
|
||||
// This will also be available in DECORATE code that inherits your class!
|
||||
default
|
||||
{
|
||||
MyCoolActor.MyCoolMember 5000;
|
||||
MyCoolActor.MyCoolMemberList 501, 502;
|
||||
}
|
||||
|
||||
// Declare some members.
|
||||
int m_MyCoolMember;
|
||||
int m_CoolMember1, m_CoolMember2;
|
||||
// Declare some members.
|
||||
int m_MyCoolMember;
|
||||
int m_CoolMember1, m_CoolMember2;
|
||||
|
||||
// Declare some properties attached to our members.
|
||||
property MyCoolMember: m_MyCoolMember;
|
||||
property MyCoolMemberList: m_CoolMember1, m_CoolMember2;
|
||||
// Declare some properties attached to our members.
|
||||
property MyCoolMember: m_MyCoolMember;
|
||||
property MyCoolMemberList: m_CoolMember1, m_CoolMember2;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -242,29 +242,29 @@ A class with some flags.
|
|||
```
|
||||
class MyCoolActorWithFlags : Actor
|
||||
{
|
||||
// You can set defined flag in a "default" block like in DECORATE.
|
||||
// This will also be available in DECORATE code that inherits your class!
|
||||
// Hey, those sentences sounded familiar...
|
||||
default
|
||||
{
|
||||
+MyCoolActorWithFlags.ThisOneIsOn
|
||||
-MyCoolActorWithFlags.ThisOneIsOff
|
||||
}
|
||||
// You can set defined flag in a "default" block like in DECORATE.
|
||||
// This will also be available in DECORATE code that inherits your class!
|
||||
// Hey, those sentences sounded familiar...
|
||||
default
|
||||
{
|
||||
+MyCoolActorWithFlags.ThisOneIsOn
|
||||
-MyCoolActorWithFlags.ThisOneIsOff
|
||||
}
|
||||
|
||||
// Declare a flag field for all of the flags. This can hold up to 32 flags.
|
||||
int m_Flags;
|
||||
// Declare a flag field for all of the flags. This can hold up to 32 flags.
|
||||
int m_Flags;
|
||||
|
||||
// Declare the flags, one at a time...
|
||||
flagdef ThisOneIsOn: m_Flags, 0;
|
||||
flagdef ThisOneIsOff: m_Flags, 1;
|
||||
flagdef ThisOneAliasesOn: m_Flags, 0;
|
||||
// Declare the flags, one at a time...
|
||||
flagdef ThisOneIsOn: m_Flags, 0;
|
||||
flagdef ThisOneIsOff: m_Flags, 1;
|
||||
flagdef ThisOneAliasesOn: m_Flags, 0;
|
||||
|
||||
// Unnecessary, since you can just access it directly, but this demonstrates
|
||||
// how declared flags can be used in methods.
|
||||
bool CheckIfOnIsOn()
|
||||
{
|
||||
return bThisOneIsOn;
|
||||
}
|
||||
// Unnecessary, since you can just access it directly, but this demonstrates
|
||||
// how declared flags can be used in methods.
|
||||
bool CheckIfOnIsOn()
|
||||
{
|
||||
return bThisOneIsOn;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -281,7 +281,7 @@ ZScript, for syntax flexibility purposes, it must be enclosed in a block with
|
|||
```
|
||||
default
|
||||
{
|
||||
$[Default-statement...]$
|
||||
$[Default-statement...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -333,7 +333,7 @@ A state definition block has the syntax:
|
|||
```
|
||||
states $[ ( Scope $[ , Scope]$... ) ]$
|
||||
{
|
||||
$[State-or-label...]$
|
||||
$[State-or-label...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ An enumeration definition takes the form:
|
|||
```
|
||||
enum Identifier $[ : Integer-type]$
|
||||
{
|
||||
$[Enumerator $[ , Enumerator]$... $[ , ]$]$
|
||||
$[Enumerator $[ , Enumerator]$... $[ , ]$]$
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -39,20 +39,20 @@ Identifier $[ = Expression]$
|
|||
// Basic enumeration.
|
||||
enum MyCoolEnum
|
||||
{
|
||||
A_THING, // Has value int(0) ...
|
||||
BEES, // ... 1 ...
|
||||
CALCIUM, // ... 2 ...
|
||||
DEXTROSE, // ... and 3.
|
||||
A_THING, // Has value int(0) ...
|
||||
BEES, // ... 1 ...
|
||||
CALCIUM, // ... 2 ...
|
||||
DEXTROSE, // ... and 3.
|
||||
}
|
||||
|
||||
// Less trivial example.
|
||||
enum MyCoolerEnum : int16
|
||||
{
|
||||
A = 500, // Has value int16(500),
|
||||
B, // 501,
|
||||
C = 200,
|
||||
D, // 201,
|
||||
E, // and 202.
|
||||
A = 500, // Has value int16(500),
|
||||
B, // 501,
|
||||
C = 200,
|
||||
D, // 201,
|
||||
E, // and 202.
|
||||
}
|
||||
```
|
||||
<!-- EOF -->
|
||||
|
|
|
@ -23,7 +23,7 @@ Methods are formed as so:
|
|||
```
|
||||
$[Method-definition-flags...]$ Type $[ , Type]$... Identifier ( $[Method-argument-list]$ ) $[ const ]$
|
||||
{
|
||||
$[Statement...]$
|
||||
$[Statement...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ A compound statement is formed as:
|
|||
|
||||
```
|
||||
{
|
||||
$[Statement...]$
|
||||
$[Statement...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -78,17 +78,17 @@ if ( Expression ) Statement $[ else Statement]$
|
|||
// Simple conditional.
|
||||
|
||||
if(a)
|
||||
B();
|
||||
B();
|
||||
|
||||
// Simple conditional, with else statement and a block.
|
||||
|
||||
if(a)
|
||||
{
|
||||
B();
|
||||
c = d;
|
||||
B();
|
||||
c = d;
|
||||
}
|
||||
else
|
||||
e = f;
|
||||
e = f;
|
||||
```
|
||||
|
||||
# Switch Statements
|
||||
|
@ -108,17 +108,17 @@ switch ( Expression ) Statement
|
|||
switch(a)
|
||||
{
|
||||
case 500:
|
||||
Console.PrintF("a is 500");
|
||||
break;
|
||||
Console.PrintF("a is 500");
|
||||
break;
|
||||
case 501:
|
||||
Console.PrintF("a is 501");
|
||||
// Falls through to the next case.
|
||||
Console.PrintF("a is 501");
|
||||
// Falls through to the next case.
|
||||
case 502:
|
||||
Console.PrintF("a is 501 or 502");
|
||||
break;
|
||||
Console.PrintF("a is 501 or 502");
|
||||
break;
|
||||
default:
|
||||
Console.PrintF("not sure what a is!");
|
||||
// "break" is implied here.
|
||||
Console.PrintF("not sure what a is!");
|
||||
// "break" is implied here.
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -152,11 +152,11 @@ iteration is complete. The `do while` and `do until` loops are formed as such:
|
|||
|
||||
```
|
||||
do
|
||||
Statement
|
||||
Statement
|
||||
while ( Expression ) // unlike C, you don't need a semicolon here
|
||||
|
||||
do
|
||||
Statement
|
||||
Statement
|
||||
until ( Expression )
|
||||
```
|
||||
|
||||
|
@ -195,47 +195,47 @@ return $[Expression $[ , Expression]$...]$ ;
|
|||
// Use of "continue."
|
||||
for(int i = 0; i < 50; i++)
|
||||
{
|
||||
// Don't do anything when "i" is 25.
|
||||
if(i == 25)
|
||||
continue;
|
||||
// Don't do anything when "i" is 25.
|
||||
if(i == 25)
|
||||
continue;
|
||||
|
||||
DoThing(i);
|
||||
DoThing(i);
|
||||
}
|
||||
|
||||
// Use of "break."
|
||||
for(int i = 0; i < 50; i++)
|
||||
{
|
||||
// "break" when "i" is 25.
|
||||
if(i == 25)
|
||||
break;
|
||||
// "break" when "i" is 25.
|
||||
if(i == 25)
|
||||
break;
|
||||
|
||||
DoThing(i);
|
||||
DoThing(i);
|
||||
}
|
||||
|
||||
// Use of `return` in various contexts.
|
||||
void ReturnsNothing()
|
||||
{
|
||||
// Exit early if "m_Thing" isn't 50.
|
||||
if(m_Thing != 50)
|
||||
return;
|
||||
// Exit early if "m_Thing" isn't 50.
|
||||
if(m_Thing != 50)
|
||||
return;
|
||||
|
||||
DoThing(m_Thing);
|
||||
DoThing(m_Thing);
|
||||
}
|
||||
|
||||
int ReturnsInt()
|
||||
{
|
||||
// "m_Thing" is 50, so return 50.
|
||||
if(m_Thing == 50)
|
||||
return 50;
|
||||
// "m_Thing" is 50, so return 50.
|
||||
if(m_Thing == 50)
|
||||
return 50;
|
||||
|
||||
// Must have a return, eventually.
|
||||
return 0;
|
||||
// Must have a return, eventually.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int, int ReturnsTwoInts()
|
||||
{
|
||||
// Returns 1 and 2.
|
||||
return 1, 2;
|
||||
// Returns 1 and 2.
|
||||
return 1, 2;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ A structure takes the form of:
|
|||
```
|
||||
struct Identifier $[Structure-flags...]$
|
||||
{
|
||||
$[Structure-content...]$
|
||||
$[Structure-content...]$
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -39,9 +39,9 @@ Optionally followed by a semicolon.
|
|||
// Simple structure.
|
||||
struct MyCoolStructure
|
||||
{
|
||||
int X;
|
||||
int Y;
|
||||
int Z;
|
||||
int X;
|
||||
int Y;
|
||||
int Z;
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -235,8 +235,8 @@ so the following:
|
|||
```
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
array<int> a;
|
||||
a.Push(0);
|
||||
array<int> a;
|
||||
a.Push(0);
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue