Difference between revisions of "AGS tidbits & snippets"

From Adventure Game Studio | Wiki
Jump to navigationJump to search
(Added new info about String arrays)
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
<small>(Transferred from [http://www.strazer.net/ags/tidbits.htm strazer's original page])</small>
 
 
 
Aside from all the great ideas and scripts I've found after browsing through the whole beginners and technical forum, I noticed the small things either not in the manual or easy to miss.
 
Aside from all the great ideas and scripts I've found after browsing through the whole beginners and technical forum, I noticed the small things either not in the manual or easy to miss.
  
Line 13: Line 11:
 
==General==
 
==General==
  
'''CJ''': "There's no hard limit, but a '''sprite cannot be taller than the screen''' resolution."
+
'''CJ''': There's no hard limit, but a '''sprite cannot be taller than the screen''' resolution.
 
----
 
----
'''CJ''': "(...) if you put a room file called '_blank.crm' in your game folder, it will be used as the '''template for New Room'''"
+
'''CJ''': If you put a room file called "_blank.crm" in your game folder, it will be used as the '''template for new rooms'''. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=18963.msg231484#msg231484]
([http://www.bigbluecup.com/yabb/index.php?topic=18963.msg231484#msg231484 Thread])
 
 
----
 
----
'''CJ''': "Yep, adding a '''blank dialog option will make it unclickable''' (...)"
+
'''CJ''': Adding a '''blank dialog option will make it unclickable'''. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=18958.msg231475#msg231475]
([http://www.bigbluecup.com/yabb/index.php?topic=18958.msg231475#msg231475 Thread])
 
 
:''So you can use that as default dialog option that gets run when all others have been turned off.''
 
:''So you can use that as default dialog option that gets run when all others have been turned off.''
 
----
 
----
'''CJ''': "No, most of the '''data (i.e. rooms and sprites) is only loaded when needed'''."
+
'''CJ''': Most of the '''data (i.e. rooms and sprites) is only loaded when needed'''. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=18541.msg225790#msg225790]
([http://www.bigbluecup.com/yabb/index.php?topic=18541.msg225790#msg225790 Thread])
 
 
----
 
----
'''bonordberg''': "(...) AGS only allows '''35 or so characters and objects on the screen at the same time'''."
+
'''bonordberg''': AGS only allows 35 or so '''characters and objects on the screen at the same time'''. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=15513.msg190266#msg190266]
([http://www.bigbluecup.com/yabb/index.php?topic=15513.msg190266#msg190266 Thread])
 
 
:''AGS v2.62 '''increased the limit to 50'''.''
 
:''AGS v2.62 '''increased the limit to 50'''.''
 
----
 
----
'''CJ''': "(...) you could '''double-click the "Edit this .AGSGame" file''' to open the game in the editor.
+
'''CJ''': You could '''double-click the "Edit this .AGSGame" file''' to open the game in the editor.<br>
You can create this association manually if you like, just set up .AGSGame files so that their association is:
+
You can create this association manually if you like, just set up .AGSGame files so that their association is: [http://www.adventuregamestudio.co.uk/forums/index.php?topic=12051.msg166879#msg166879]
  
 
  c:\path\to\ags\agsedit.exe -shelllaunch "%1"
 
  c:\path\to\ags\agsedit.exe -shelllaunch "%1"
 
([http://www.bigbluecup.com/yabb/index.php?topic=12051.msg166879#msg166879 Thread])
 
 
----
 
----
'''CJ''': "You cannot load a '''game saved at a different resolution'''."
+
'''CJ''': You '''cannot load a game saved at a different resolution'''.
 
:''So start playing your low-res game in hi-res if you intend to switch to bigger-sized windowed mode later.''
 
:''So start playing your low-res game in hi-res if you intend to switch to bigger-sized windowed mode later.''
 
----
 
----
'''CJ''': "The AGS editor can '''only automatically use 16-colour icons'''."
+
<strike>'''CJ''': The AGS editor can '''only automatically use 16-colour icons'''. ([http://www.bigbluecup.com/tracker.php?action=detail&id=153 Tracker])</strike>
([http://www.bigbluecup.com/tracker.php?action=detail&id=153 Tracker])
+
:''As of AGS v2.72 hi-color icons can be used when running Windows 2000/XP.''
 
----
 
----
'''CJ''': "'''Labels and text boxes have a maximum length of 200 [characters],''' just like the max string length."
+
'''CJ''': '''Labels and text boxes have a maximum length of 200 characters,''' just like the max string length. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=13914.msg168605#msg168605]
([http://www.bigbluecup.com/yabb/index.php?topic=13914.msg168605#msg168605 Thread])
 
 
----
 
----
'''CJ''': "'''Tiled sprite import''' now goes from left to right in rows (...)"
+
'''CJ''': '''Tiled sprite import''' now goes from left to right in rows.
 
----
 
----
'''Scorpiorus''': "You can have about '''150 lines of text [in a listbox].'''"
+
'''Scorpiorus''': You can have about '''150 lines of text in a listbox.'''
 
----
 
----
'''CJ''': "'''You can have up to 1000 rooms''', but any numbered &gt;300 will not have their state saved when the player leaves the room.
+
'''CJ''': '''You can have up to 1000 rooms''', but any numbered >300 will not have their state saved when the player leaves the room. This basically means that room script variables, object positions, etc will all be reset to their default values when you leave the room. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=13914.msg168605#msg168605]
This basically means that room script variables, object positions, etc will all be reset to their default values when you leave the room."
 
([http://www.bigbluecup.com/yabb/index.php?topic=13914.msg168605#msg168605 Thread])
 
 
----
 
----
'''CJ''': "'''Beta versions of the engine are larger''', because they don't have all the debug code stripped out, and aren't compressed."
+
'''CJ''': '''Beta versions of the engine are larger''', because they don't have all the debug code stripped out, and aren't compressed. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=12051.msg150828#msg150828]
([http://www.bigbluecup.com/yabb/index.php?topic=12051.msg150828#msg150828 Thread])
 
 
----
 
----
'''CJ''': "(...) '''#define is replaced with its definition''' at compile-time (...)"
+
'''CJ''': '''#define is replaced with its definition''' at compile-time. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=13234.msg158627#msg158627]
([http://www.bigbluecup.com/yabb/index.php?topic=13234.msg158627#msg158627 Thread])
 
 
----
 
----
'''CJ''': "'''AGS v2.3 and later request 85 Hz''' from DirectX."
+
'''CJ''': '''AGS v2.3 and later request 85 Hz''' from DirectX.
 
----
 
----
'''Erica McLane''': "'''Games compiled for DOS have 60 Hz''' (...)"
+
'''Erica McLane''': '''Games compiled for DOS have 60 Hz'''.
 
----
 
----
'''CJ''': "[When '''creating a translation source''', AGS] only scans backwards 10 characters to check for the 'GetxxxProperty' (...)"
+
'''CJ''': When '''creating a translation source''', AGS only scans backwards 10 characters to check for the 'GetxxxProperty'. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=13043.msg156462#msg156462]
([http://www.bigbluecup.com/yabb/index.php?topic=13043.msg156462#msg156462 Thread])
 
 
----
 
----
'''CJ''': "[Regarding '''fatal exceptions''' ] (...) eip +5997 means the MP3 player and eip +379 means a problem drawing the GUI (...)"
+
'''CJ''': '''Fatal exceptions''' eip +5997 mean the MP3 player and eip +379 mean a problem drawing the GUI. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=12798.msg153456#msg153456]
([http://www.bigbluecup.com/yabb/index.php?topic=12798.msg153456#msg153456 Thread])
 
 
----
 
----
'''Esseb''': "(...) 320*200 which is what the game engine reverts to '''if no config file is present'''."
+
'''Esseb''': 320*200 is what the game engine reverts to '''if no config file is present'''. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=12787.msg153098#msg153098]
([http://www.bigbluecup.com/yabb/index.php?topic=12787.msg153098#msg153098 Thread])
 
 
----
 
----
'''CJ''': "(...) to ensure [the pathfinder] always works, your '''walkable areas should always be at least 3 pixels wide'''."
+
'''CJ''': To ensure [the pathfinder] always works, your '''walkable areas should always be at least 3 pixels wide'''.
 
:''I suppose the same applies to non-walkable areas.''
 
:''I suppose the same applies to non-walkable areas.''
 
----
 
----
<del>
+
<del>'''Gilbot''': '''Sprites are always stored in the basic executable''', the splitted resources only contain room data.</del>
'''Gilbot''': "'''Sprite datas are always stored in the basic executable''', the splitted resources only contain room data."
 
</del>
 
 
:''As of AGS v2.7, sprite data is stored in the first splitted resource file.''
 
:''As of AGS v2.7, sprite data is stored in the first splitted resource file.''
 
----
 
----
 
<del>
 
<del>
'''CJ''': "'''The inventory window currently keeps track of the order that items are added to it''', until (...) the player character is changed, at which point the items switch back to the default order."
+
'''CJ''': '''The inventory window currently keeps track of the order that items are added to it''', until the player character is changed, at which point the items switch back to the default order. [http://www.adventuregamestudio.co.uk/forums/index.php?topic=12870.msg153895#msg153895]
([http://www.bigbluecup.com/yabb/index.php?topic=12870.msg153895#msg153895 Thread])
 
 
</del>
 
</del>
 
:''As of AGS v2.7, the inventory item order for each character is remembered.''
 
:''As of AGS v2.7, the inventory item order for each character is remembered.''
 
----
 
----
'''CJ''': "The '''dialog options are drawn in the player character's talking colour'''. The highlighted option colour uses the GUI foreground colour if you are using a GUI TextWindow, otherwise it is hardcoded to yellow."
+
'''CJ''': The '''dialog options are drawn in the player character's talking colour'''. The highlighted option colour uses the GUI foreground colour if you are using a GUI TextWindow, otherwise it is hardcoded to yellow. ([http://www.bigbluecup.com/tracker.php?action=detail&id=172 Tracker])
([http://www.bigbluecup.com/tracker.php?action=detail&id=172 Tracker])
 
 
----
 
----
'''CJ''': "(...) '''Character.UnlockView doesn't change the loop number back''', so he will go to facing in whichever direction the loop that was playing in the animation was."
+
'''CJ''': '''Character.UnlockView doesn't change the loop number back''', so he will go to facing in whichever direction the loop that was playing in the animation was.
 
----
 
----
'''CJ''': "'''Character.FaceLocation''' will only allow [a character] to face directions which he can actually walk in."
+
'''CJ''': '''Character.FaceLocation''' will only allow a character to face directions which he can actually walk in.
 
----
 
----
'''inFERNo''': "...'''every interaction in the [interaction editor] list is executed first''', the run script always when all others are done."
+
'''inFERNo''': '''Every interaction in the interaction editor list is executed first''', the run script always when all others are done.
 
----
 
----
'''CJ''': "The '''maximum room height''' is 1400 pixels (at 320x200 resolution - you could have a 2800-tall 640x400 room)."
+
'''CJ''': The '''maximum room height''' is 1400 pixels (at 320x200 resolution - you could have a 2800-tall 640x400 room).
 
:''I asked CJ for clarification:''
 
:''I asked CJ for clarification:''
'''CJ''': "The pathfinder uses an 1400-sized array for storing potential routes, and there's one row for each line."
+
'''CJ''': The pathfinder uses an 1400-sized array for storing potential routes, and there's one row for each line.
 
:''That means in 320x200 and 320x240 the maximum room background height is 1400 pixels, in 640x400, 640x480 and 800x600 it's 2800 pixels. In theory, there's no width limit.''
 
:''That means in 320x200 and 320x240 the maximum room background height is 1400 pixels, in 640x400, 640x480 and 800x600 it's 2800 pixels. In theory, there's no width limit.''
 
----
 
----
'''CJ''': "(...) '''objects are placed with 320x240-res co-ordinates''', so at 640x480 you can only place them on even pixels."
+
'''CJ''': '''Objects are placed with 320x240-res co-ordinates''', so at 640x480 you can only place them on even pixels.
 
:''Keep this in mind when designing your backgrounds/objects!''
 
:''Keep this in mind when designing your backgrounds/objects!''
  
 
==Scripting==
 
==Scripting==
  
'''CJ''': "'''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."
+
'''CJ''': '''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. [http://www.bigbluecup.com/yabb/index.php?topic=21763.msg265903#msg265903]
([http://www.bigbluecup.com/yabb/index.php?topic=21763.msg265903#msg265903 Thread])
 
 
----
 
----
'''CJ''': "I'd just like to clarify that there is '''no point in using a short rather than an int as a local variable'''.  
+
'''CJ''': I'd just like to clarify that 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. [http://www.bigbluecup.com/yabb/index.php?topic=21214.msg259479#msg259479]
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."
 
([http://www.bigbluecup.com/yabb/index.php?topic=21214.msg259479#msg259479 Thread])
 
 
----
 
----
'''CJ''': "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."
+
'''CJ''': 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. [http://www.bigbluecup.com/yabb/index.php?topic=21191.msg258882#msg258882]
([http://www.bigbluecup.com/yabb/index.php?topic=21191.msg258882#msg258882 Thread])
 
 
----
 
----
'''CJ''': "The workaround for '''displaying player-entered strings''', in case anyone wants to know, is simply to do this:
+
'''CJ''': The workaround for '''displaying player-entered strings''', in case anyone wants to know, is simply to do this:
 
  Display("%s", playerString);
 
  Display("%s", playerString);
since that way, the player string will not be parsed for special tokens."
+
since that way, the player string will not be parsed for special tokens. [http://www.bigbluecup.com/yabb/index.php?topic=12051.msg157449#msg157449]
([http://www.bigbluecup.com/yabb/index.php?topic=12051.msg157449#msg157449 Thread])
 
 
----
 
----
'''CJ''': "(...) you have to '''place the export after the variable's declaration''' (...)"
+
'''CJ''': You have to '''place the export after the variable's declaration'''. [http://www.bigbluecup.com/yabb/index.php?topic=18972.msg231473#msg231473]
([http://www.bigbluecup.com/yabb/index.php?topic=18972.msg231473#msg231473 Thread])
 
 
:''So you don't necessarily have to put the exports at the '''end''' of scripts.''
 
:''So you don't necessarily have to put the exports at the '''end''' of scripts.''
 
----
 
----
'''CJ''': "Yes, the script engine has a '''limit of 9 parameters in a function call'''."
+
'''CJ''': You should be able to have '''up to 15 parameters to a function'''. [http://www.bigbluecup.com/yabb/index.php?topic=27727.msg352543#msg352543]
 
----
 
----
'''CJ''': "Note that '''optional parameters only work with int and enum''' parameters, you can't do it with strings or floats."
+
'''CJ''': Note that '''optional parameters only work with int and enum''' parameters, you can't do it with strings or floats.
 
----
 
----
'''CJ''': "It's
+
'''CJ''': Basically, to be consistent with Java/C#, '''the protection level always goes first''': [http://www.bigbluecup.com/yabb/index.php?topic=19369.msg226163#msg226163]
 
  protected import static function get_slots();
 
  protected import static function get_slots();
Basically, to be consistent with Java/C#, '''the protection level always goes first'''."
 
([http://www.bigbluecup.com/yabb/index.php?topic=19369.msg226163#msg226163 Thread])
 
 
----
 
----
'''CJ''': "You'll get [an error] if you define over '''4 KB's worth of variables inside a function'''."
+
'''CJ''': You'll get an error if you define over '''4 KB's worth of variables inside a function'''. [http://www.bigbluecup.com/yabb/index.php?topic=17550.msg215027#msg215027]
([http://www.bigbluecup.com/yabb/index.php?topic=17550.msg215027#msg215027 Thread])
 
 
----
 
----
'''CJ''': "(...) it's not until a room is loaded that the '''current viewport size''' is known."
+
'''CJ''': It's not until a room is loaded that the '''current viewport size''' is known. [http://www.bigbluecup.com/yabb/index.php?topic=12051.msg170758#msg170758]
([http://www.bigbluecup.com/yabb/index.php?topic=12051.msg170758#msg170758 Thread])
 
 
([http://www.bigbluecup.com/tracker.php?action=detail&id=470 Tracker])
 
([http://www.bigbluecup.com/tracker.php?action=detail&id=470 Tracker])
:''So better not use system.viewport_width or system.viewport_height in game_start.''
+
:''So better not rely on system.viewport_width or system.viewport_height in game_start.''
 
----
 
----
'''(Unknown)''': "You can use :''return;'' to '''abort the rest of the script'''."
+
'''(Unknown)''': You can use :''return;'' to '''abort the rest of the script'''.
 
----
 
----
'''CJ''': "'''Local room scripts have their data segment saved''' when the room is destroyed, so all variables retain their values."
+
'''CJ''': '''Local room scripts have their data segment saved''' when the room is destroyed, so all variables retain their values.
 
:''Useful to store the condition of light switches, for example.''
 
:''Useful to store the condition of light switches, for example.''
 
----
 
----
'''CJ''': "'''RunInventoryInteraction (...) doesn't get run immediately''' - instead, it gets run when the calling script finishes."
+
'''CJ''': '''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.''
 
:''Applies only if the interaction runs a script. Interaction editor commands are executed immediately.''
 
----
 
----
'''CJ''': "The '''number of game loops [speech text] stays for''' is:
+
'''CJ''': The '''number of game loops [speech text] stays for''' is: [http://www.bigbluecup.com/yabb/index.php?topic=14364.msg174988#msg174988]
 
  int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();
 
  int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();
([http://www.bigbluecup.com/yabb/index.php?topic=14364.msg174988#msg174988 Thread])
 
 
----
 
----
'''CJ''': "'''Functions cannot return structs or arrays''' - they can only return primitive types."
+
'''CJ''': '''Functions cannot return structs or arrays''' - they can only return primitive types. [http://www.bigbluecup.com/yabb/index.php?topic=13458.msg162111#msg162111]
([http://www.bigbluecup.com/yabb/index.php?topic=13458.msg162111#msg162111 Thread])
 
 
----
 
----
'''Gilbot''': "'''A [char] is a one byte integer''', so you can use = and = = directly."
+
'''Gilbot''': '''A [char] is a one byte integer''', so you can use = and = = directly. [http://www.bigbluecup.com/yabb/index.php?topic=13300.msg160466#msg160466]
([http://www.bigbluecup.com/yabb/index.php?topic=13300.msg160466#msg160466 Thread])
 
 
:''Meaning, unlike strings, you can do''
 
:''Meaning, unlike strings, you can do''
 
  char tmpchar = 'A';
 
  char tmpchar = 'A';
 
  tmpchar += 2; // will make tmpchar into 'C'
 
  tmpchar += 2; // will make tmpchar into 'C'
 
----
 
----
'''RickJ''': "A '''variable declaration in the header''' will cause a :''seperate'' [static] variable (...) for each room."
+
'''RickJ''': A '''variable declaration in the header''' will cause a ''seperate'' [static] variable for each room.
 
:''Could be used instead of room properties if you need to change them at run-time.''
 
:''Could be used instead of room properties if you need to change them at run-time.''
 
----
 
----
'''SSH''': "'''Strings in structs''' have to be declared as ''char desc [256];''"
+
'''SSH''': '''Strings in structs''' have to be declared as ''char desc [256];'' [http://www.bigbluecup.com/yabb/index.php?topic=12418.msg147974#msg147974]
([http://www.bigbluecup.com/yabb/index.php?topic=12418.msg147974#msg147974 Thread])
 
 
:''I think it's 200, the AGS maximum string length:''
 
:''I think it's 200, the AGS maximum string length:''
 
  struct myStruct {
 
  struct myStruct {
Line 175: Line 141:
 
'''Scorpiorus''':
 
'''Scorpiorus''':
 
  cJack.Say("The new code is %04d", GetGlobalInt(99));
 
  cJack.Say("The new code is %04d", GetGlobalInt(99));
(...) will '''add leading zeros''' (up to 4) if necessary."
+
will '''add leading zeros''' (up to 4) if necessary.
 
:''Here are more format flags:''
 
:''Here are more format flags:''
  
 
  // (number) = Create a field (number) characters wide:
 
  // (number) = Create a field (number) characters wide:
  Display("Here comes %4d a test", 22); //=&gt; Here comes &nbsp;&nbsp;22 a test
+
  Display("Here comes %4d a test", 22); //=> Here comes &nbsp;&nbsp;22 a test
  
 
  // - = Left justify:
 
  // - = Left justify:
  Display("Here comes %-4d a test", 22); //=&gt; Here comes 22&nbsp;&nbsp; a test
+
  Display("Here comes %-4d a test", 22); //=> Here comes 22&nbsp;&nbsp; a test
  
 
  // 0 = Field is padded with 0's instead of blanks:
 
  // 0 = Field is padded with 0's instead of blanks:
  Display("Here comes %04d a test", 22); //=&gt; Here comes 0022 a test
+
  Display("Here comes %04d a test", 22); //=> Here comes 0022 a test
  
 
  // + = Sign of number always shown:
 
  // + = Sign of number always shown:
  Display("Here comes %+d a test", 22); //=&gt; Here comes +22 a test
+
  Display("Here comes %+d a test", 22); //=> Here comes +22 a test
  
 
  // (blank) = Positive values begin with a blank:
 
  // (blank) = Positive values begin with a blank:
  Display("Here comes % d a test", 22); //=&gt; Here comes &nbsp;22 a test
+
  Display("Here comes % d a test", 22); //=> Here comes &nbsp;22 a test
 
----
 
----
'''RickJ''': "The character's '''global inventory variables are integers''' and can be used to keep track of how many items the character has."
+
'''RickJ''': The character's '''global inventory variables are integers''' and can be used to keep track of how many items the character has.
  
 
==Characters, objects & hotspots==
 
==Characters, objects & hotspots==
  
 
<del>
 
<del>
'''Scorpiorus''': "(...) the exact '''[MoveCharacterToObject]''' offsets (...) are +5 and +6 from the object's x and y respectively (...)"
+
'''Scorpiorus''': The exact '''MoveCharacterToObject offsets''' are +5 and +6 from the object's x and y respectively." [http://www.bigbluecup.com/yabb/index.php?topic=14323.msg174331#msg174331]
([http://www.bigbluecup.com/yabb/index.php?topic=14323.msg174331#msg174331 Thread])
 
 
</del>
 
</del>
 
:''This function is obsolete as of AGS v2.7''
 
:''This function is obsolete as of AGS v2.7''
 
----
 
----
'''CJ''': "A character with a '''move speed of 0 instantly warps''' to their destination."
+
'''CJ''': A character with a '''move speed of 0 instantly warps''' to their destination. [http://www.bigbluecup.com/yabb/index.php?topic=14364.msg185447#msg185447]
([http://www.bigbluecup.com/yabb/index.php?topic=14364.msg185447#msg185447 Thread])
 
 
----
 
----
'''Spyros''': "The '''default [idle view delay]''' is 20 sec."
+
'''Spyros''': The '''default idle view delay''' is 20 sec.
 
:''It's hidden in the manual.''
 
:''It's hidden in the manual.''
 
----
 
----
'''Cornjob''': "(...) '''Character.LoseInventory''' only decreases the quantity by 1."
+
'''Cornjob''': '''Character.LoseInventory''' only decreases the quantity by 1.
 
(<del>[http://p098.ezboard.com/fdosuserforumsfrm6.showMessage?topicID=220.topic ezboard-Thread]</del>)
 
(<del>[http://p098.ezboard.com/fdosuserforumsfrm6.showMessage?topicID=220.topic ezboard-Thread]</del>)
 
:'' Similarly, Character.AddInventory increases the quantity by one each time it's used.
 
:'' Similarly, Character.AddInventory increases the quantity by one each time it's used.
Line 217: Line 181:
 
  if (player.InventoryQuantity[iCoin.ID] == 1) { // if player has EXACTLY one inv item iCoin
 
  if (player.InventoryQuantity[iCoin.ID] == 1) { // if player has EXACTLY one inv item iCoin
 
----
 
----
'''CJ''': "There is an undocumented Character.on variable, which is normally 1, but you can set it to 0 to '''make the character invisible'''."
+
'''CJ''': There is an undocumented Character.on variable, which is normally 1, but you can set it to 0 to '''make the character invisible'''.
 
:''Note that Character.Walk and the like don't work with characters turned off this way.''
 
:''Note that Character.Walk and the like don't work with characters turned off this way.''
 
----
 
----
'''Scorpiorus''': "'''If the hide player option is ticked''' [the Character.on variable] holds 0."
+
'''Scorpiorus''': '''If the hide player option is ticked''' the Character.on variable holds 0. [http://www.bigbluecup.com/yabb/index.php?topic=14295.msg173897#msg173897]
([http://www.bigbluecup.com/yabb/index.php?topic=14295.msg173897#msg173897 Thread])
 
 
----
 
----
'''CJ''': "Directly modifying Character.room won't prompt a room change, it'll just '''make the player character disappear'''."
+
'''CJ''': Directly modifying Character.room won't prompt a room change, it'll just '''make the player character disappear'''.
  
 
==Multimedia==
 
==Multimedia==
  
'''CJ''': "'''If you don't want to bundle the flic's''', just put them in your Compiled folder rather than your game folder, and they won't get built into the EXE."
+
'''CJ''': '''If you don't want to bundle the flic's''', just put them in your Compiled folder rather than your game folder, and they won't get built into the EXE. [http://www.bigbluecup.com/yabb/index.php?topic=20631.msg251734#msg251734]
([http://www.bigbluecup.com/yabb/index.php?topic=20631.msg251734#msg251734 Thread])
 
 
----
 
----
'''Scorpiorus''': "(...) the '''PlayMP3File(filename) function requires the mp3 file to be in the game\compiled folder''' rather than game folder."
+
'''Scorpiorus''': The '''PlayMP3File(filename) function requires the mp3 file to be in the game\compiled folder''' rather than game folder.
 
:''I think this is in the manual. However, I find it worth repeating.''
 
:''I think this is in the manual. However, I find it worth repeating.''
 
----
 
----
'''CJ''': "The ''''Play music on room load'''' only accepts music numbers from 1-120.
+
'''CJ''': The ''''Play music on room load'''' textbox only accepts music numbers from 1-120.
To play a higher numbered music, you need to use PlayMusic."
+
To play a higher numbered music, you need to use PlayMusic.
 
----
 
----
'''CJ''': "'''Music 0 is automatically played at game startup.'''"
+
'''CJ''': '''Music 0 is automatically played at game startup.'''
 
:''Works with compiled games, too.'' :)
 
:''Works with compiled games, too.'' :)
 
----
 
----
'''(Unknown)''': "If you import 24-bit pictures in AGS, it will '''automatically convert to [16-bit]'''."
+
'''(Unknown)''': If you import 24-bit pictures in AGS, it will '''automatically convert to [16-bit]'''.
 
:''Just import 24-bit pictures into your high-color game.''
 
:''Just import 24-bit pictures into your high-color game.''
 
----
 
----
 
'''Windows default sound volume''': All sliders to 50%
 
'''Windows default sound volume''': All sliders to 50%
 
----
 
----
'''CJ''': "(...) AGS doesn't actually use [Media Player] itself [to '''play avi videos'''], but it uses the same [DirectShow] that MP does."
+
'''CJ''': AGS doesn't actually use Media Player itself to '''play avi videos''', it just uses the same DirectShow that Media Player does.
 
----
 
----
'''Scorpiorus''': "(...) [if music disabled or no sound card] '''GetMP3PosMills()''' always returns 0 (...)"
+
'''Scorpiorus''': If music has been disabled or there's no sound card, '''GetMP3PosMills()''' always returns 0.
  
 
==Miscellaneous==
 
==Miscellaneous==
  
'''CJ''': "You can '''disable the abort key''' by doing: game.abort_key = -1;"
+
'''CJ''': You can '''disable the abort key''' by doing: ''game.abort_key = -1;'' [http://www.bigbluecup.com/yabb/index.php?topic=18139.msg220807#msg220807]
([http://www.bigbluecup.com/yabb/index.php?topic=18139.msg220807#msg220807 Thread])
 
 
:''Please don't. If your game locks up, the user won't be able to abort.''
 
:''Please don't. If your game locks up, the user won't be able to abort.''
 
----
 
----
 
In dialog scripts, the ''''...' will pause for 1 second''' (regardless of game speed setting).
 
In dialog scripts, the ''''...' will pause for 1 second''' (regardless of game speed setting).
 
----
 
----
'''CJ''': "(...) [calling "game.exe --setup"] is '''all that the winsetup.exe program does'''."
+
'''CJ''': Calling "game.exe --setup" is '''all that the winsetup.exe program does'''.
 
----
 
----
'''CJ''': "You can '''rename winsetup.exe to anything you like''', it will still work."
+
'''CJ''': You can '''rename winsetup.exe to anything you like''', it will still work.
 
----
 
----
 
Character to '''mask % symbol in strings''': %
 
Character to '''mask % symbol in strings''': %
Line 275: Line 236:
 
==Assorted==
 
==Assorted==
  
'''Scorpiorus''': "(...) blocking commands block the text script but not the interaction editor's actions."
+
'''Scorpiorus''': Blocking commands block the text script but not the interaction editor's actions." [http://www.bigbluecup.com/yabb/index.php?topic=14676.msg179442#msg179442]
([http://www.bigbluecup.com/yabb/index.php?topic=14676.msg179442#msg179442 Thread])
 
 
----
 
----
'''CJ''': "The linux engine can play any games created with AGS v2.5 and later."
+
'''CJ''': The linux engine can play any games created with AGS v2.5 and later. [http://www.bigbluecup.com/yabb/index.php?topic=14384.msg174948#msg174948]
([http://www.bigbluecup.com/yabb/index.php?topic=14384.msg174948#msg174948 Thread])
 
 
----
 
----
'''CJ''': "(...) in the editor AGS has to convert the 16-bit images to 15-bit for display (or for clipboard copy)."
+
'''CJ''': In the editor AGS has to convert the 16-bit images to 15-bit for display (or for clipboard copy). [http://www.bigbluecup.com/yabb/index.php?topic=11001.msg171794#msg171794]
([http://www.bigbluecup.com/yabb/index.php?topic=11001.msg171794#msg171794 Thread])
 
 
----
 
----
'''CJ''': "Set your desktop colour depth to 32-bit, then run winsetup and select to run the game in a window.
+
'''CJ''': Set your desktop colour depth to 32-bit, then run winsetup and select to run the game in a window.
Then, you can launch ACWIN (or any AGS game) with the parameter '--15bit' (without the speech marks), which will '''force it into 15-bit mode'''."
+
Then, you can launch ACWIN (or any AGS game) with the parameter "--15bit" (without the speech marks), which will '''force it into 15-bit mode'''. [http://www.bigbluecup.com/yabb/index.php?topic=13721.msg166897#msg166897]
([http://www.bigbluecup.com/yabb/index.php?topic=13721.msg166897#msg166897 Thread])
 
 
----
 
----
'''CJ''': "'''Object.MergeIntoBackground is effectively RawDrawObject''' followed by Object.Visible = false (...)"
+
'''CJ''': '''Object.MergeIntoBackground is effectively RawDrawObject''' followed by ''Object.Visible = false;''. [http://www.bigbluecup.com/yabb/index.php?topic=12051.msg166879#msg166879]
([http://www.bigbluecup.com/yabb/index.php?topic=12051.msg166879#msg166879 Thread])
 
 
----
 
----
'''CJ''': "(...) '''with TTF fonts the full 256 characters are supported''' (but not unicode, sorry)."
+
'''CJ''': '''With TTF fonts the full 256 characters are supported''' (but not unicode, sorry).
 
:''Works only using translations, not directly.''
 
:''Works only using translations, not directly.''
 
----
 
----
'''CJ''': "(...) GUI names actually #define to a special '''hidden function FindGUIByName''', so that even if the numbers have changed, it will still find the right one."
+
'''CJ''': GUI names actually #define to a special '''hidden function FindGUIByName''', so that even if the numbers have changed, it will still find the right one. [http://www.bigbluecup.com/yabb/index.php?topic=13234.msg158627#msg158627]
([http://www.bigbluecup.com/yabb/index.php?topic=13234.msg158627#msg158627 Thread])
 
 
----
 
----
'''Gilbot''': "(...) '''FLICs are limited to 256 colours''' (...)"
+
'''Gilbot''': '''FLICs are limited to 256 colours'''.
 
:''FLI supports only one resolution: 320x200 with 256 colors
 
:''FLI supports only one resolution: 320x200 with 256 colors
 
FLC supports any resolution up to 1024x768 with 256 colors.''
 
FLC supports any resolution up to 1024x768 with 256 colors.''
 
----
 
----
'''Scorpiorus''': "AGS moves characters only when all scripts are finished."
+
'''Scorpiorus''': AGS moves characters only when all scripts are finished.
 
----
 
----
'''CJ''': "Only characters, objects, mouse cursors and GUI backgrounds support being drawn with an alpha channel in-game."
+
'''CJ''': Only characters, objects, mouse cursors and GUI backgrounds support being drawn with an alpha channel in-game.
 
:''You can have '''alpha-channel GUI buttons''' if you use a GUI background image that has no background layer.''
 
:''You can have '''alpha-channel GUI buttons''' if you use a GUI background image that has no background layer.''
 
----
 
----
'''CJ''': "If the conversation is launched from a global script function (eg. the character interaction) then repeatedly_execute doesn't run in the background (...)"
+
'''CJ''': If the conversation is launched from a global script function (eg. the character interaction) then repeatedly_execute doesn't run in the background.
 
:''Is this still true?''
 
:''Is this still true?''
  
 
==See also==
 
==See also==
 
* [[:Category:Tidbits and Snippets|Tidbits and Snippets]] - Better organized version of this page (may not be complete yet). Use this when adding new stuff.
 
* [[:Category:Tidbits and Snippets|Tidbits and Snippets]] - Better organized version of this page (may not be complete yet). Use this when adding new stuff.
 +
 +
[[Category:Scripting]]

Latest revision as of 23:54, 28 January 2014

Aside from all the great ideas and scripts I've found after browsing through the whole beginners and technical forum, I noticed the small things either not in the manual or easy to miss.

I have sorted through my notes and thought I'd post what I've found, maybe some of you will find this useful at one point or another.

Please don't add anything to this page, add to the Tidbits and Snippets category instead.

Enjoy,

strazer


General

CJ: There's no hard limit, but a sprite cannot be taller than the screen resolution.


CJ: If you put a room file called "_blank.crm" in your game folder, it will be used as the template for new rooms. [1]


CJ: Adding a blank dialog option will make it unclickable. [2]

So you can use that as default dialog option that gets run when all others have been turned off.

CJ: Most of the data (i.e. rooms and sprites) is only loaded when needed. [3]


bonordberg: AGS only allows 35 or so characters and objects on the screen at the same time. [4]

AGS v2.62 increased the limit to 50.

CJ: You could double-click the "Edit this .AGSGame" file to open the game in the editor.
You can create this association manually if you like, just set up .AGSGame files so that their association is: [5]

c:\path\to\ags\agsedit.exe -shelllaunch "%1"

CJ: You cannot load a game saved at a different resolution.

So start playing your low-res game in hi-res if you intend to switch to bigger-sized windowed mode later.

CJ: The AGS editor can only automatically use 16-colour icons. (Tracker)

As of AGS v2.72 hi-color icons can be used when running Windows 2000/XP.

CJ: Labels and text boxes have a maximum length of 200 characters, just like the max string length. [6]


CJ: Tiled sprite import now goes from left to right in rows.


Scorpiorus: You can have about 150 lines of text in a listbox.


CJ: You can have up to 1000 rooms, but any numbered >300 will not have their state saved when the player leaves the room. This basically means that room script variables, object positions, etc will all be reset to their default values when you leave the room. [7]


CJ: Beta versions of the engine are larger, because they don't have all the debug code stripped out, and aren't compressed. [8]


CJ: #define is replaced with its definition at compile-time. [9]


CJ: AGS v2.3 and later request 85 Hz from DirectX.


Erica McLane: Games compiled for DOS have 60 Hz.


CJ: When creating a translation source, AGS only scans backwards 10 characters to check for the 'GetxxxProperty'. [10]


CJ: Fatal exceptions eip +5997 mean the MP3 player and eip +379 mean a problem drawing the GUI. [11]


Esseb: 320*200 is what the game engine reverts to if no config file is present. [12]


CJ: To ensure [the pathfinder] always works, your walkable areas should always be at least 3 pixels wide.

I suppose the same applies to non-walkable areas.

Gilbot: Sprites are always stored in the basic executable, the splitted resources only contain room data.

As of AGS v2.7, sprite data is stored in the first splitted resource file.

CJ: The inventory window currently keeps track of the order that items are added to it, until the player character is changed, at which point the items switch back to the default order. [13]

As of AGS v2.7, the inventory item order for each character is remembered.

CJ: The dialog options are drawn in the player character's talking colour. The highlighted option colour uses the GUI foreground colour if you are using a GUI TextWindow, otherwise it is hardcoded to yellow. (Tracker)


CJ: Character.UnlockView doesn't change the loop number back, so he will go to facing in whichever direction the loop that was playing in the animation was.


CJ: Character.FaceLocation will only allow a character to face directions which he can actually walk in.


inFERNo: Every interaction in the interaction editor list is executed first, the run script always when all others are done.


CJ: The maximum room height is 1400 pixels (at 320x200 resolution - you could have a 2800-tall 640x400 room).

I asked CJ for clarification:

CJ: The pathfinder uses an 1400-sized array for storing potential routes, and there's one row for each line.

That means in 320x200 and 320x240 the maximum room background height is 1400 pixels, in 640x400, 640x480 and 800x600 it's 2800 pixels. In theory, there's no width limit.

CJ: Objects are placed with 320x240-res co-ordinates, so at 640x480 you can only place them on even pixels.

Keep this in mind when designing your backgrounds/objects!

Scripting

CJ: 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. [14]


CJ: I'd just like to clarify that 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. [15]


CJ: 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. [16]


CJ: The workaround for displaying player-entered strings, in case anyone wants to know, is simply to do this:

Display("%s", playerString);

since that way, the player string will not be parsed for special tokens. [17]


CJ: You have to place the export after the variable's declaration. [18]

So you don't necessarily have to put the exports at the end of scripts.

CJ: You should be able to have up to 15 parameters to a function. [19]


CJ: Note that optional parameters only work with int and enum parameters, you can't do it with strings or floats.


CJ: Basically, to be consistent with Java/C#, the protection level always goes first: [20]

protected import static function get_slots();

CJ: You'll get an error if you define over 4 KB's worth of variables inside a function. [21]


CJ: It's not until a room is loaded that the current viewport size is known. [22] (Tracker)

So better not rely on system.viewport_width or system.viewport_height in game_start.

(Unknown): You can use :return; to abort the rest of the script.


CJ: Local room scripts have their data segment saved when the room is destroyed, so all variables retain their values.

Useful to store the condition of light switches, for example.

CJ: 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.

CJ: The number of game loops [speech text] stays for is: [23]

int gameloops = ((StrLen(text) / game.text_speed) + 1) * GetGameSpeed();

CJ: Functions cannot return structs or arrays - they can only return primitive types. [24]


Gilbot: A [char] is a one byte integer, so you can use = and = = directly. [25]

Meaning, unlike strings, you can do
char tmpchar = 'A';
tmpchar += 2; // will make tmpchar into 'C'

RickJ: A variable declaration in the header will cause a seperate [static] variable for each room.

Could be used instead of room properties if you need to change them at run-time.

SSH: Strings in structs have to be declared as char desc [256]; [26]

I think it's 200, the AGS maximum string length:
struct myStruct {
  char mystring [200];
};
Since you can't make arrays from string variables, you can make it from such a struct instead. (AGS v2.71's new String type works as an array.)

Scorpiorus:

cJack.Say("The new code is %04d", GetGlobalInt(99));

will add leading zeros (up to 4) if necessary.

Here are more format flags:
// (number) = Create a field (number) characters wide:
Display("Here comes %4d a test", 22); //=> Here comes   22 a test
// - = Left justify:
Display("Here comes %-4d a test", 22); //=> Here comes 22   a test
// 0 = Field is padded with 0's instead of blanks:
Display("Here comes %04d a test", 22); //=> Here comes 0022 a test
// + = Sign of number always shown:
Display("Here comes %+d a test", 22); //=> Here comes +22 a test
// (blank) = Positive values begin with a blank:
Display("Here comes % d a test", 22); //=> Here comes  22 a test

RickJ: The character's global inventory variables are integers and can be used to keep track of how many items the character has.

Characters, objects & hotspots

Scorpiorus: The exact MoveCharacterToObject offsets are +5 and +6 from the object's x and y respectively." [27]

This function is obsolete as of AGS v2.7

CJ: A character with a move speed of 0 instantly warps to their destination. [28]


Spyros: The default idle view delay is 20 sec.

It's hidden in the manual.

Cornjob: Character.LoseInventory only decreases the quantity by 1. (ezboard-Thread)

Similarly, Character.AddInventory increases the quantity by one each time it's used.

So better use

if (player.InventoryQuantity[iCoin.ID]) { // if player has one OR MORE of inv item iCoin
instead of
if (player.InventoryQuantity[iCoin.ID] == 1) { // if player has EXACTLY one inv item iCoin

CJ: There is an undocumented Character.on variable, which is normally 1, but you can set it to 0 to make the character invisible.

Note that Character.Walk and the like don't work with characters turned off this way.

Scorpiorus: If the hide player option is ticked the Character.on variable holds 0. [29]


CJ: Directly modifying Character.room won't prompt a room change, it'll just make the player character disappear.

Multimedia

CJ: If you don't want to bundle the flic's, just put them in your Compiled folder rather than your game folder, and they won't get built into the EXE. [30]


Scorpiorus: The PlayMP3File(filename) function requires the mp3 file to be in the game\compiled folder rather than game folder.

I think this is in the manual. However, I find it worth repeating.

CJ: The 'Play music on room load' textbox only accepts music numbers from 1-120. To play a higher numbered music, you need to use PlayMusic.


CJ: Music 0 is automatically played at game startup.

Works with compiled games, too. :)

(Unknown): If you import 24-bit pictures in AGS, it will automatically convert to [16-bit].

Just import 24-bit pictures into your high-color game.

Windows default sound volume: All sliders to 50%


CJ: AGS doesn't actually use Media Player itself to play avi videos, it just uses the same DirectShow that Media Player does.


Scorpiorus: If music has been disabled or there's no sound card, GetMP3PosMills() always returns 0.

Miscellaneous

CJ: You can disable the abort key by doing: game.abort_key = -1; [31]

Please don't. If your game locks up, the user won't be able to abort.

In dialog scripts, the '...' will pause for 1 second (regardless of game speed setting).


CJ: Calling "game.exe --setup" is all that the winsetup.exe program does.


CJ: You can rename winsetup.exe to anything you like, it will still work.


Character to mask % symbol in strings: %

Display("The %% is the percent symbol.");

Character to mask quotemarks in strings: \

Display("The \" is a quotemark.");

Character for line breaks in strings: [

Display("The [ is a line break.");

Character to mask [ in strings: \

Display("The \[ is a left brace.");

Assorted

Scorpiorus: Blocking commands block the text script but not the interaction editor's actions." [32]


CJ: The linux engine can play any games created with AGS v2.5 and later. [33]


CJ: In the editor AGS has to convert the 16-bit images to 15-bit for display (or for clipboard copy). [34]


CJ: Set your desktop colour depth to 32-bit, then run winsetup and select to run the game in a window. Then, you can launch ACWIN (or any AGS game) with the parameter "--15bit" (without the speech marks), which will force it into 15-bit mode. [35]


CJ: Object.MergeIntoBackground is effectively RawDrawObject followed by Object.Visible = false;. [36]


CJ: With TTF fonts the full 256 characters are supported (but not unicode, sorry).

Works only using translations, not directly.

CJ: GUI names actually #define to a special hidden function FindGUIByName, so that even if the numbers have changed, it will still find the right one. [37]


Gilbot: FLICs are limited to 256 colours.

FLI supports only one resolution: 320x200 with 256 colors

FLC supports any resolution up to 1024x768 with 256 colors.


Scorpiorus: AGS moves characters only when all scripts are finished.


CJ: Only characters, objects, mouse cursors and GUI backgrounds support being drawn with an alpha channel in-game.

You can have alpha-channel GUI buttons if you use a GUI background image that has no background layer.

CJ: If the conversation is launched from a global script function (eg. the character interaction) then repeatedly_execute doesn't run in the background.

Is this still true?

See also

  • Tidbits and Snippets - Better organized version of this page (may not be complete yet). Use this when adding new stuff.