Difference between revisions of "Manual:DIL Manual/gamestate()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = gamestate() = | |
| + | '''Procedure.''' Takes a player out of the game to the menu, back into the game, or out altogether. | ||
| − | + | gamestate(pc : unitptr, gs : integer) | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | The menu is where a player is between connecting and playing; basis.zon's login program enters the game with <code>gamestate(self, GS_PLAY)</code>. In the menu the character is out of the world: in no room, not in the list of players, out of reach of everyone. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| − | + | |- | |
| + | | pc || unitptr || A player. | ||
| + | |- | ||
| + | | gs || integer || One of the GS_ values in vme.h, below. | ||
| + | |} | ||
| − | + | {| class="wikitable" | |
| − | + | ! Value !! What happens | |
| − | + | |- | |
| − | + | | GS_PLAY (0) || Into the game: at the room the player was in when they left for the menu, or at their hometown. Their inventory is loaded from file and their DIL programs start again. Nothing happens if they are already playing. | |
| − | + | |- | |
| − | + | | GS_QUIT (1) || Out of the game: as GS_MENU, and then the character is destroyed. | |
| − | + | |- | |
| − | + | | GS_MENU (2) || Out to the menu: the player is saved (unless an unsaved guest), their inventory is taken away, they leave the room, and every DIL program on them stops except the one that called gamestate. Nothing happens if they are already in the menu. | |
| − | + | |- | |
| + | | GS_LINK_DEAD (3) || Closes the player's connection. | ||
| + | |} | ||
| − | + | == Notes == | |
| + | * Players only. On an NPC the program stops with "DIL SERIOUS: ... Type error in gamestate: Not a pc unit" in the log. A null unit stops it too ("Type error in gamestate"). | ||
| + | * Any other number does nothing. | ||
| + | * In the menu every line the player types goes to the programs on the player only, and never runs as a command. The program that called gamestate reads it with <code>wait(SFB_CMD, activator == self)</code> and command() or excmdstr, as competition.zon's menu does. | ||
| + | * A player in the menu can't be seen, attacked or found, so a menu open to mortals is a place to hide; keep such menus short. | ||
| + | * vmc reports a wrong second argument as "Arg 1 of 'gamestate' not an integer". | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin do_backstage(arg : string); | |
| + | code | ||
| + | { | ||
| + | if (self.type != UNIT_ST_PC) | ||
| + | quit; | ||
| + | gamestate(self, GS_MENU); | ||
| − | + | :menu: | |
| − | < | + | sendtext("<br/>1) Back to the game<br/>2) Show the time<br/>Make your choice: ", self); |
| + | wait(SFB_CMD, activator == self); | ||
| + | block; | ||
| − | + | if (command("1")) | |
| − | + | { | |
| − | + | gamestate(self, GS_PLAY); | |
| − | + | exec("look", self); | |
| − | + | quit; | |
| − | + | } | |
| − | + | if (command("2")) | |
| − | + | sendtext("It is mud hour " + itoa(mudhour) + ".<br/>", self); | |
| − | + | goto menu; | |
| − | + | } | |
| − | |||
| − | |||
| − | |||
| − | |||
dilend | dilend | ||
| + | </pre> | ||
| + | A player command (<code>func = do_backstage@zone</code> in commands.def) that takes the player to a small menu and back into the game when they type 1, as competition.zon does. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/command()|command()]] | |
| − | + | * [[Manual:DIL Manual/excmdstr|excmdstr]] | |
| − | + | * [[Manual:DIL Manual/exec()|exec()]] | |
| − | + | * [[Manual:DIL Manual/wait()|wait()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:19, 14 November 2026
gamestate()
Procedure. Takes a player out of the game to the menu, back into the game, or out altogether.
gamestate(pc : unitptr, gs : integer)
The menu is where a player is between connecting and playing; basis.zon's login program enters the game with gamestate(self, GS_PLAY). In the menu the character is out of the world: in no room, not in the list of players, out of reach of everyone.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | A player. |
| gs | integer | One of the GS_ values in vme.h, below. |
| Value | What happens |
|---|---|
| GS_PLAY (0) | Into the game: at the room the player was in when they left for the menu, or at their hometown. Their inventory is loaded from file and their DIL programs start again. Nothing happens if they are already playing. |
| GS_QUIT (1) | Out of the game: as GS_MENU, and then the character is destroyed. |
| GS_MENU (2) | Out to the menu: the player is saved (unless an unsaved guest), their inventory is taken away, they leave the room, and every DIL program on them stops except the one that called gamestate. Nothing happens if they are already in the menu. |
| GS_LINK_DEAD (3) | Closes the player's connection. |
Notes
- Players only. On an NPC the program stops with "DIL SERIOUS: ... Type error in gamestate: Not a pc unit" in the log. A null unit stops it too ("Type error in gamestate").
- Any other number does nothing.
- In the menu every line the player types goes to the programs on the player only, and never runs as a command. The program that called gamestate reads it with
wait(SFB_CMD, activator == self)and command() or excmdstr, as competition.zon's menu does. - A player in the menu can't be seen, attacked or found, so a menu open to mortals is a place to hide; keep such menus short.
- vmc reports a wrong second argument as "Arg 1 of 'gamestate' not an integer".
Example
dilbegin do_backstage(arg : string);
code
{
if (self.type != UNIT_ST_PC)
quit;
gamestate(self, GS_MENU);
:menu:
sendtext("<br/>1) Back to the game<br/>2) Show the time<br/>Make your choice: ", self);
wait(SFB_CMD, activator == self);
block;
if (command("1"))
{
gamestate(self, GS_PLAY);
exec("look", self);
quit;
}
if (command("2"))
sendtext("It is mud hour " + itoa(mudhour) + ".<br/>", self);
goto menu;
}
dilend
A player command (func = do_backstage@zone in commands.def) that takes the player to a small menu and back into the game when they type 1, as competition.zon does.