Scripting hints

From Adventure Game Studio | Wiki
Revision as of 12:18, 1 December 2005 by *>SSH
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


  • Keys that aren't listed in the ASCII Code Table have no guarantees about their keycode numbers and may well overlap keys that are listed.

Thread

  • there is no point in using a short rather than an int as a local variable. In fact, ints are faster because the CPU is better at reading/writing 32-bit chunks of memory than it is at 16-bit chunks.

Thread

  • There is no fixed limit on the size of global arrays, but as scotch says they use up memory so don't go silly with creating massive ones unless you really need to

Thread

  • The workaround for displaying player-entered strings, in case anyone wants to know, is simply to do the following, since that way, the player string will not be parsed for special tokens.
Display("%s", playerString);

Thread

  • You have to place the export after the variable's declaration (...), So you don't necessarily have to put the exports at the end of scripts.

Thread

  • Parameters to functions can be made optional by adding a default value in the import of the function. This even works if you are not actually exporting the function.
import function myfun (int a, int b=5);  // optional int b
  • Note that optional parameters only work with int and enum parameters, you can't do it with strings or floats
  • Basically, to be consistent with Java/C#, the protection level always goes first when using protected functions:
protected import static function get_slots();

Thread

  • it's not until a room is loaded that the current viewport size is known. So better not use system.viewport_width or system.viewport_height in game_start.

Thread - Tracker

  • You can use return; to abort the rest of the script.
  • Local room scripts have their data segment saved when the room is destroyed, so all variables retain their values (for rooms 1-300 only) Useful to store the condition of light switches, for example.
  • RunInventoryInteraction (...) doesn't get run immediately - instead, it gets run when the calling script finishes. Applies only if the interaction runs a script. Interaction editor commands are executed immediately.
  • The number of game loops [speech text] stays for is:
int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();

Thread

  • Functions cannot return structs or arrays - they can only return primitive types. This includes Strings in the latest 2.71 beta.
  • The character's global inventory variables are integers and can be used to keep track of how many items the character has.