1. unit 10 ags tutorial 2303cy5
TRANSCRIPT
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
1/71
Unit 10 Game Development 2 Page 1 of 71
Unit 10Game Development 2
Creating an Educational Titleusing
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
2/71
Unit 10 Game Development 2 Page 2 of 71
Initial Setup
At the first window, select Start a New Game and click continue At the Start New Game Wizard Click Next
At the Template Window, select Default Game. For your own game try any of theavailable templates
At the New Game Details window, give your new game an appropriate name.o For this example, something like First game, Tutorial or Example would be
appropriate.
Then enter the file name for the executable. Keep it to 8 characters maximum.
o Again keep it appropriate, like Example etc.o Your project game will have its own appropriate name
Then set the folder where the game will be stored during its creation.o Set this to your external USB drive or your H:\ drive
Click Finish and after a little but you will be presented with the AGS interface ready fordevelopment
Ongoing / Subsequent editing
For subsequent editing of your game, when your open AGS, you can either select;o Continue an existing game, and browse for its location.o Or if your game is showing in the Recently Edited Game list, you can select it,
and click Continue a Recently edited game, and click continue.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
3/71
Unit 10 Game Development 2 Page 3 of 71
Configuring the General Settings
Now we have the game started, the first changes we need to make are to the GeneralSettings for the game. These control things such as colour depth, character movement, textoutput and other settings which are required for setting up the game.
To access the General Settings, simply double-click the General Settings node in theProject Tree.
Project Tree
Properties Grid
The General Settings Page opens allowing you to configure the setup of the gameMake the following changes under the relevant headings
(Setup)Colour depth : 32-bit Resolution : 320 x 200By specifying this resolution, it means that you will need to create all of your background
images to match this resolution. If you want to have higher resolution, you need to specify ithere as well as create higher resolution background images.NOTE:We set the actual screen size of the game later using the Runtime Engine Setupprogram.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
4/71
Unit 10 Game Development 2 Page 4 of 71
DialogSpeech style : Lucasarts
Text-outputAnti-alias TTF fonts : True
VisualEnable Letterbox mode : True
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
5/71
Unit 10 Game Development 2 Page 5 of 71
PART 1 Daves RoomPART 1 Daves Room
Characters
By default the game comes with only one character, cEgo, who is quite an unattractive sprite.We will need to import (and later for your project, create) our own characters.
In the Project Tree expand the Characters node. You should see the default charactercalled cEgo underneath the tree.
Import a new character by Right-clicking on theCharacters node and selecting Import Character
Navigate to the characters folder and open Dave.chaThe character cDave will now appear under the Characters node.The Convention for naming characters is cName_of_character
Double-Click on cDave to view his properties.
You need to click here to make Davethe Players character
Drag the handle to resizethe Property Grid
View charactersanimations
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
6/71
Unit 10 Game Development 2 Page 6 of 71
Examining Daves Properties
StartY: Initial osition
StartX: Initial x osition
Startin Room: The room that Dave starts in
Scri tName: How Dave is referred to in scri t
The Property Grid shows all the properties forthe selected item.
Import the following characters the same way you imported Dave.Import the following characters the same way you imported Dave.
Baron.cha Baron.cha Mika.cha Mika.cha Max.cha Max.cha
Chris.cha Chris.cha
As we no longer need cEgo delete him by right-clicking on him and selecting delete if youAs we no longer need cEgo delete him by right-clicking on him and selecting delete if you
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
7/71
Unit 10 Game Development 2 Page 7 of 71
Rooms
Expand the Rooms node in the Project tree to reveal the defaultroom in the game. Right Click on Room and Click New Room.You can then delete Room 0 by right clicking on it and clickingDelete this room.
Now expand the 1: node and double-click on Edit room.
Naming the Room:
In the Properties Window change theDescription to Daves room.
The Room Editor itself is currently blank (as shown Below)
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
8/71
Unit 10 Game Development 2 Page 8 of 71
Import a Background:
The first thing we need to do is import a background.
Ensure that Background to display: is set to main Background and click on the Changebutton.
Navigate to the backgrounds folder and select Davys Room.bmp
The Background Preview Window will now show the imported background
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
9/71
Unit 10 Game Development 2 Page 9 of 71
Game Setup
At this stage we can test our game and see how it looks
Before we run it though we need to run the Game Setup. This is a two part process.
Start by selecting Build Build EXE (F7) from the menu bar.Once the game has compiled select Build Run Game Setup
Choose the settings shown below.
It is at this point that you change the graphics filter to 2x nearest-neighbour filter. This willchange the Resolution to 640x400.
(Note that some of the options may be different depending upon your PC. Also some PCs may notsupport all the options available. You will need to experiment to find the best settings for your PC).
Press Save and Run
If everything went well your game should run. If there are any error messages, simply re-runthe game setup and change the options In particular the graphics driver and filter used
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
10/71
Unit 10 Game Development 2 Page 10 of 71
Playing the game
When you are playing an AGS game your mouse cursor is replaced by an icon representingthe mode you are in. The default mode shown (Walk to) allows you to direct the player aroundthe screen by left-clicking where you want the player to walk to.
Right-Clicking allows you to change the cursor mode between the following modes
Walk to
Look at
Interact with
Talk to
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
11/71
Unit 10 Game Development 2 Page 11 of 71
Use the Walk-to mode to direct your player around the screen.
You will notice that wherever you click your player walks, even on top of the bed and on walls.
To define where characters are allowed to walk within a room we need to define what arecalled walkable areas.
Close the game and return to the Room editor
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
12/71
Unit 10 Game Development 2 Page 12 of 71
Walkable Areas
To define walkable areas you need to choose theWalkable areas option from the drop-down menu.
You create walkable areas by simply filling in theareas you want to be walkable with the drawing
tools provided. AGS provides Line, Freehand,Rectangle and Fill tools.
Use the left mouse button with these drawing tools provided to make a walkable area similarto that shown. Dont worry about the bit that is in front of the bed post at this point. Well fix itshortly.
Because it is the bottom middle ofthe character that is used to checkthese areas you should create theareas slightly smaller than they need
Walkable Area
Test your game by pressing the Run button OR by pressing F5.
Your character should now only be able to walk on the areas you defined.The player will be able to walk anywhere covered with a coloured blue rectangle(s).
If for some reason you want to edit or delete the walkable areas, select the Rectangle tool
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
13/71
Unit 10 Game Development 2 Page 13 of 71
Walk-Behind Areas
The next task is to define the walk-behind areas.
When testing your game you may have noticed that when the characterwalks past the bedpost at the top they are drawn in front of the post.
Walk-behind areas tell the game where the character needs to be drawn behind thebackground image. In this case, behind the bedpost.
From the drop-down box choose Walk-behinds.
Use the drawing tools to create an area over the bedpost.
Setting a baseline
To make our walk-behind work we have to create a baseline which defines where the playerhas to be in order to be drawn behind the walk-behind area.
You set the baseline by moving the mouse cursor to the bottom of the walk-behind area andreading the y coordinate. You then type this number into the baseline property of the walk-behind.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
14/71
Unit 10 Game Development 2 Page 14 of 71
Get y coordinate here
Enter y coordinate
x y
Hold mouse cursor
Test your game. This time when the character walks behind the post, they should be drawnbehind it.
Debugging
You can view the walkable areas of the game while you are playing it by pressing CTRL-A.
CTRL-D will provide you with some information about the current room.
CTRL-X will allow you to teleport to another room.
There are other debugging features available which will be explored once we do somescripting.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
15/71
Unit 10 Game Development 2 Page 15 of 71
Interaction
While the character can walk around, they cannot do anything else. We need to add someinteraction to our game.
There are three things that characters can interact with in AGS Hotspots, objects andother characters.
We will start with hotspots
Hotspots
We will create two hotspots. One on the picture on Daves wall and
the other on the window.
To add a hotspot make sure you are in the room editor and selectHotspots from the same drop-down menu that you chose Walkable-areas and Walk-behinds from.
Create a hotspot over the picture using the drawing tools the sameway you added a walkable-area.
Now that we have defined a hotspot we need to provide itwith a Name and a Description.
A hotspot is an area of the background image that the player can look at and interact with.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
16/71
Unit 10 Game Development 2 Page 16 of 71
To add another hotspot select the drop-down of the selected hotspot and choosehHotspot2.To add another hotspot select the drop-down of the selected hotspot and choosehHotspot2.
Because the first hotspot is no longer selected it is drawn in grey.
Draw the second hotspot over thewindow.
Define the following properties
Description: Daves WindowName: hwindow
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
17/71
Unit 10 Game Development 2 Page 17 of 71
Walk To Points
When the player uses the look-at mode to look at a hotspot we want the character to walk tothe hotspot. We can set this up through the walk-to-point property for each hotspot.
Select the hpicture hotspot from the selector
To work out the location where you want the character to walk to when you look at or interactwith the hotspot move the mouse cursor (crosshair) to the location on the background whereyou want your character to walk to.
Read the Mouse Position located under the Change button. The 1st number is the xlocation while the 2nd number is the y location.
Type this number into the WalkToPoint in the properties for the
hotspot.
Repeat this process to place a WalkToPoint for when Dave interactswith the Window.
Test your game. Check that when you use the look-at mode to interact with both the picture
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
18/71
Unit 10 Game Development 2 Page 18 of 71
Scripting
Make sure the hotspot hpicture is selected, and then click on the Events button
The Property Grid changes to reveal all the events for the hotspot.
EVENTS occur when the player does something in thegame.
At the moment there are no events set up.
When the player looks at the picture we want 2 events tooccur.
1. Dave faces the picture2. Dave speaks
Click on the row and then click on the button with the three dotsthat appears.
The script editor opens with a function that will run when thelook-at mode is used on the hpicture hotspot.
Type the following script in-between the curly brackets
cDave.FaceLocation(211, 53);
Since AGS 3.0, all the interactivity in the game is handled using scripts.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
19/71
Unit 10 Game Development 2 Page 19 of 71
As you are typing you will notice that you are given code hints to help you choose thecommand you are looking for.As you are typing you will notice that you are given code hints to help you choose thecommand you are looking for.
This script tells the character cDave to face the location211,53.This script tells the character cDave to face the location211,53.
The location was obtained the same way a WalkToPoint was (Bysimply holding the mouse cursor over the location we want Dave toface).
The location was obtained the same way a WalkToPoint was (Bysimply holding the mouse cursor over the location we want Dave toface).
Test your game.Test your game.
Dave should now face the picture after he first walks to the WalkToPoint.Dave should now face the picture after he first walks to the WalkToPoint.
Now it is time to make Dave talk. Before Dave actually speaks we will display a message totell the player what Dave is looking at.Now it is time to make Dave talk. Before Dave actually speaks we will display a message totell the player what Dave is looking at.
After the command for making Dave face the picture add the following commands.After the command for making Dave face the picture add the following commands.
Display("It's a picture of James Hetfield from Metallica");Display("It's a picture of James Hetfield from Metallica");
cDave.Say("I Love this picture");cDave.Say("I Love this picture");
Test your game to view the result.Test your game to view the result.
Display("It's a picture of James Hetfield from Metallica");Display("It's a picture of James Hetfield from Metallica"); cDave.Say("I Love this picture");cDave.Say("I Love this picture");
Displays a message to the screen. It is displayed in the standardmessage box, and centered in the middle of the screen. It will onlybe removed when the player clicks or presses a key
Displays the message as speech above the character'shead. Only appears for a limited time.
The default style that is used to display the character speech is set up in the General Settings
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
20/71
Unit 10 Game Development 2 Page 20 of 71
Other Display Options
DisplayAtY (5, "It's a picture of James Hetfield from Metallica");
Similar to the Display function, except that this will display the message box at the specified Y
location on the screen. The Y defines the co-ordinate of the top of the message box.
DisplayAt (180,30,100, "It's a picture of James Hetfield from Metallica");
Identical to the "Display" function, only this allows you to define the position and size of the
window where the text is displayed. The X and Y variables define the co-ordinates of the upper-left
corner of the window. The above message will be displayed at coordinates 180 ,30 in a box 100 pixels wide.
DisplayTopBar(25, 8, 7, "Narrator", "It's a picture of James Hetfield from
Metallica");
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
21/71
Unit 10 Game Development 2 Page 21 of 71
Displays a message in a text window, with a caption bar on top of it. The 2nd number (8) is the textcolour and the 3rd number is the back colour (Light grey) of the caption.
cEgo.SpeechColor = 10;
cDave.Say("I Love this picture");
Gets/sets the character's speech text color. The initial colour is set up in the characters property
grid.
cDave.SayAt(120, 20, 100, "I Love this picture");
Similar to Say , except that the text is displayed with its top left corner at (X,Y), in an area WIDTH
wide.
SetSpeechStyle(eSpeechSierra);
cDave.Say("I Love this picture");
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
22/71
Unit 10 Game Development 2 Page 22 of 71
We now need to repeat this process so that when Dave looks out the window, Dave faces thecorrect location and we get an appropriate message displayed. What you do is up to you.We now need to repeat this process so that when Dave looks out the window, Dave faces thecorrect location and we get an appropriate message displayed. What you do is up to you.
Perhaps something like this. (Notice it occurs in the EVENT of an Anyclick on hotspot)Perhaps something like this. (Notice it occurs in the EVENT of an Anyclick on hotspot)
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
23/71
Unit 10 Game Development 2 Page 23 of 71
PART 2 The Rest of the Game Starting with the Hallway &Inventories
OK, moving on, we need to create the rest of the house. Well startby creating a new room.
To create a new room right-click on the Rooms node and select New room
Import the background image hallway.bmp
In the Properties Grid assign Hallway as
the Room Description.
Create a Walkable area that will allowcharacters to walk on the carpet anddown the stairs.
Scaling walkable areas
In rooms like this one which have a significant Z axis variance (ie depth) to them, it is a goodidea to set up scaling in the walkable areas. This is used so that the characters grows in sizeas they get closer, and appear to walk off into the distance by shrinking. This is used toprovide an artificial 3D effect to a 2D room.
To do this, make sure the rooms walkable areas arebeing shown, then in the scaling properties, changeUseContinuousScaling to True. This will reveal two
new parameters of MaxScalingLevel andMinScalingLevel. For this room, set Max to 100 andMin to 85.
NOTE: Your MaxScalingLevel can actually be greater than 100
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
24/71
Unit 10 Game Development 2 Page 24 of 71
Making characters change room
For Dave to leave the room we want him to use the interact mode (the hand) on the Door in
his room.
We will set this up now.
Open the editing window for Room 1.
Select the next available hotspot and give it theproperties shown on the left.
Create a hotspot that covers the door and a walktopoint near the foot of the door.
Click on the Events button for the hotspot and select theInteract hotspot Event.
Click on the button to open the script editor.
Once again a function is created to handle the event.
Add the following script between the curly brackets
cDave.ChangeRoom(2,211,145);
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
25/71
Unit 10 Game Development 2 Page 25 of 71
The ChangeRoom function
The ChangeRoom function changes the room the character is in. You can also set the x
and y coordinates for where the character will be positioned when they enter the room
cDave.ChangeRoom(2,211,145) will move the character cDave to Room 2 at x
coordinates 211,145.
Transitions
You can also specify what transition to use as the game changes between rooms.
On the line directly before the ChangeRoom function add one of the following commands. Allfuture transitions will use the transition specified until it is changed.
SetNextScreenTransition(eTransitionBoxout);
SetNextScreenTransition(eTransitionFade);
SetNextScreenTransition(eTransitionDissolve);
SetNextScreenTransition(eTransitionCrossfade);
SetNextScreenTransition(eTransitionFade);
At this point you also need to set up a change room function for walking back from theHallway (Room 2) to the Bedroom (Room 1)
Youll need a hotspot and walkto point for the hallway door. Youll then need an Interact hotspot function when you click with the hand on the door.
This will need appropriate x,y coordinates for the arrival point in the bedroom.
Its a good habit to get into to create the appropriate change room functions as soon as yout h
U i 10 G D l 2 P 26 f 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
26/71
Unit 10 Game Development 2 Page 26 of 71
Room 2
In Room 2, Dave finds a credit card lying on the floor. When Dave picks the card up it isadded to his inventory so that he can use it later.
The first thing we need to do is import the graphics required.
Double-Click on the Sprites Node
The Sprites that are used in the game are displayed in folders onthe left.
Right-Click in the whitespace and choose Import new sprite from file
Select ccard.bmp from the Objects folder
The Import Sprite Dialogue Box opens
Accept the defaults and press Import Whole Image
Unit 10 Game Development 2 Page 27 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
27/71
Unit 10 Game Development 2 Page 27 of 71
Right-Click on the background room image and select New Object Here
A picture of a blue cup appears. This is the default object graphic (thesymbol for AGS).
We simply need to replace this with the picture of our credit card.
Select the blue cup and in the properties grid click on theimage property.
Now click on the button.
All the sprites available in your game are shown. Choose thecredit card sprite and select Use this Sprite.
The image of the cup is replaced with the credit card sprite.
Give the credit card a Description and the Name: oCreditCard.
Unit 10 Game Development 2 Page 28 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
28/71
Unit 10 Game Development 2 Page 28 of 71
Return to Room 2 and the Credit Card should be a more realistic size. Note howeverthat the size of the Credit Card object shown in the hallway in the development window isdifferent (much larger) than it is shown when the game is compiled and run. Dont let this foolyou. You always need to test you game to see what it will look likewhen it is compiled and
run.
The last thing we need to do is set the baseline for the card. Change the baseline property to5 so that it is always drawn behind Dave, and so that Daveis not drawn behind the card. To do this, SetBaselineOverriden to True and Baseline to 5.
Picking up Objects
Now that we have an object for Dave to pick up we need to create an inventory item for it.At the moment the card is simply an object. Inventory items are totally separate from roomobjects.
Items which the player can carry need to be set as inventory items.
Inventory Items
In the Project Tree double-click on the Inventory Items node.
There are currently two inventory items in there a keyand a poster. These are there by default
To add a new inventory item right-click on the inventoryitems node and select New Inventory Item.
In the Properties Grid for the new item give it the
Description: Credit Card and the Name: iCard.
Unit 10 Game Development 2 Page 29 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
29/71
Unit 10 Game Development 2 Page 29 of 71
Click on Image and thenClick on Image and then
Choose the Credit Card Sprite from the Sprite Windowand select Use this Sprite
(You must do this step so that you have a visible item inthe inventory. If you dont do this, when you select theobject in the inventory your cursor will disappear)
You now have an inventory item that can be used. When Dave interacts with the credit cardOBJECT we will give him the credit card INVENTORY ITEM.
Go back to the Objects pane of the Room Editor for Room 2.
Click on the Events Button in the Properties Grid.
Click on the button in the Interact Object event.
There are basically 2 things that we need to do when Dave interacts with the card
Unit 10 Game Development 2 Page 30 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
30/71
p g
Type the following script in the oCreditCard functionType the following script in the oCreditCard function
function oCreditCard_Interact()function oCreditCard_Interact()
{{
oCreditCard.Visible = false;oCreditCard.Visible = false;cDave.AddInventory(iCard);cDave.AddInventory(iCard);
}}
Run your Game and use the Interact_mode (the Hand) to pick up the Credit Card.Run your Game and use the Interact_mode (the Hand) to pick up the Credit Card.
Once the Credit Card has disappeared move the mouse cursor to the top of the game screento reveal the menu bar.Once the Credit Card has disappeared move the mouse cursor to the top of the game screento reveal the menu bar.
Click on the Suitcase icon to reveal Daves inventory items.Click on the Suitcase icon to reveal Daves inventory items.
The Credit Card appears in the list of inventory items.
Click on the Credit card to select it. The mouse cursor is replaced by the card.(As long as you selected an image for the inventory item in the earlier steps)
Click OK.
The credit card becomes one of your Modes which you can cycle through byright-clicking.
In the Inventory Window you will also notice a magnifying glass. This is sothat you can Look at your inventory items. We need to add an event howeverfor what happens when it is used on an inventory item.
In the Project Tree open the inventory node and double-click on iCard.
Select the Event button and click on Look at inventory item
Unit 10 Game Development 2 Page 31 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
31/71
The Global script is responsible for handling game events such as inventory items andcharacters which are not confined to specific rooms.
Add the script shown below between the { } of the function that is created.Add the script shown below between the { } of the function that is created.
function iCard_Look()function iCard_Look()
{{
Display("It's your Credit Card");Display("It's your Credit Card");
}}
Now when you run the game and use the magnifying glass to look at the Credit Card themessage Its your Credit Cardwill be displayed.Now when you run the game and use the magnifying glass to look at the Credit Card themessage Its your Credit Cardwill be displayed.
Tidying up the Credit Card pickup
At the moment Dave can pick up the credit card from anywhere in the
room. He doesnt walk to the card first. Lets tidy this up so that whenDave interacts with the card object he first walks to it and then says amessage before picking it up.
Open the Rooms node (Hallway) in the Project Tree and double-clickon the Room Script for Room 2 Hallway.
Add the following commands shown in italicsto the oCreditCard_Interact()function.
function oCreditCard_Interact()
{
cDave.Walk(180, 140, eBlock);
cDave.FaceObject(oCreditCard);
cDave.Say("What is my Credit Card doing here");
cDave.Say("I better pick that up");
Wait(40);
oCreditCard.Visible = false;
cDave.AddInventory(iCard);
}
Make sure you put the Walk, Face and Say actions before the Inventory action, as theseactions occur in the sequence they are written in the script.
Unit 10 Game Development 2 Page 32 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
32/71
Lets examine the commands
1. cDave.Walk(180, 140, eBlock);
This is the command to tell a character to walk to a location in a room. It requires 3parameters.
X location (180)
Y location 9140)
Blocking (eBlock)
Blocking can be either eNoBlock (the default) or eBlock.
eNoBlock returns the control immediately to the next line in the script meaning that the character will move inthe background while the script continues to run.
eBlock will wait for the character to finish moving before returning control to the script and running the nextcommand.
2. cDave.FaceObject(oCreditCard);
This command will make Dave face the object specified (oCreditcard).
3. cDave.Say("What is my Credit Card doing here");
cDave.Say("I better pick that up");
These commands we have already used before. They simply show Dave talking. Rememberthat you can change the text colour if you want.
4. Wait(40);
This command simply pauses the script for the given time measured in loops.
There are 40 loops/second. Therefore a value of 40 will pause the game for 1 second.
Unnecessary Default Inventory Items
Unit 10 Game Development 2 Page 33 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
33/71
Combining Inventory Items
First, create the sprite for the new object that will be created by combining inventory objects.
Now, in Inventory Items, choose one of the items that will be combined (in this example well
use the key) and click on the Events Button
In Events, choose Use inventory on this item
Add the followingfunction iKey_UseInv()
{
if (player.ActiveInventory==inventory [2])
{ cDave.Say ("Cool, look at the thingy I just made");
cDave.Say ("Dunno what it does, but its cool");
cDave.AddInventory (iThingy);
cDave.LoseInventory (iKey);
cDave.LoseInventory (iPoster);
}
else
{cDave.Say ("That's not gonna work");}
}
PART 3 The next room videos & invisible objects
Room 3 : The Laundry
You should be able to complete the following 3 steps by referring to previous sections of thistutorial
1. Create a new room with the following properties
Background: laundry room.bmp Description: laundry
2. Create an appropriate walkable area
3. Set up hotspots for the doors so that Dave can walk into the laundry from the hallway andback into the hallway from the laundry. Do not forget to set walktopoints
Unit 10 Game Development 2 Page 34 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
34/71
Multiple BackgroundsMultiple Backgrounds
Dryer door closed Dryer door open
To import another background into a room select the drop down menu shown and choose
Choose laundry room2.bmp
By default when there are more than 2 backgrounds to a room the game will cycle through therooms to create the illusion of animation. This is not what we are after though. We only wantthe second background to be shown once Dave has used the Credit Card on the Dryer.
We need to set the background to the main backgroundwhen Dave first enters the room.
Open the Events for the Room and select Enters room
Rooms in your game can have up to 5 backgrounds. These can be used for animating the
screen or changing scenes in the same room. For example, going from night to day. In ourgame when Dave is in the laundry room and he opens the dryer with his credit card wewant to show a background with the Dryer door open.
Unit 10 Game Development 2 Page 35 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
35/71
This command sets the Background image to (0) the main background.
Unit 10 Game Development 2 Page 36 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
36/71
Hotspots and Interactions
Add a hotspot to the door on the Dryer on the right and setup awalktopoint.
Setup the following interactions
Dave Looks at the hotspot Dave says It looks like there issomething in there
Dave interacts with the hotspot Dave says It doesnt want to open
Using Inventory items on Hotspots
The next event we need to setup is for when Dave uses the Credit Card on the hotspot.
In the events window for the hotspot select the event Use inventory on hotspot
Add the following commands to the function
function hDryer_UseInv()
{
if (player.ActiveInventory == inventory[3])
{SetBackgroundFrame(1);
}
}
This is called a conditional statementor an ifstatement.
It is used to check a condition and then only perform the commands inside the { } IF the
statement is TRUE.
In this case we are checking IF the player is using inventory item 3 the Credit Card. IF theyare THEN the background frame is set to 1, which is the second image showing the dryerdoor open.
Unit 10 Game Development 2 Page 37 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
37/71
Ensuring only the Correct Inventory item works on a given Hotspot
The example above where the credit card is used to open the dryer is a perfect example.Another more complicated example is when you want only a certain item to be able to unlock
a locked door.
In this case you would do the following.
First set the variable (for whether it has beeninteracted with ) in the global script andexport the variable.
Then, in the room where the action takesplaces, import the variable
Then write the function for using thecorrect inventory item on hotspot.
In this example function, use an if then
else statement, using theplayer.activeinventory script and theinventory item number to set thecondition.
Very importantly, set the variable now to 1
Finally, write the function for simplyinteracting with or looking at the hotspot.
Again in this function, use an if then else
Unit 10 Game Development 2 Page 38 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
38/71
The iPod
We want to do more than just show the second background image though. Inside the dryershould be Daves iPod.
To achieve this we will add an object to represent the iPod and simply make it visible whenthe second background is displayed.
The iPod will not be an inventory item however, therefore we only need a sprite to represent
the object.
Import the Sprite
Open the spites node in the Project Tree and right-click inthe white space and choose Import new sprite fromfile
Select iPod_small.png
Say YES to use the Alpha channel and select the top-leftpixel as the transparent colour.
Add an Object to the Laundry room
Open the laundry room in the editor and use the drop-down selector to choose objects.
Right-Click anywhere in the room and select New object here
Unit 10 Game Development 2 Page 39 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
39/71
Replace the image of the blue cup with the iPod sprite by clicking on image in theproperties grid and selecting the iPod sprite.
Place the iPod object in the dryer window.
Unit 10 Game Development 2 Page 40 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
40/71
Making an Object Invisible
We do not want the iPod to be visible until the dryer has been opened.
When Dave first enters the room we want the iPod to be invisible.
Open the Events for the laundry room and choose the Enters room before fade in event.
Add the following command to the function. The room_Load() function runs as soon as theroom loads
function room_Load()
{
object[0].Visible = false;
}
This command simply sets the visible property of object[0] (which is the iPod) to falsetherefore making it invisible.
While you have the room3 script open find the hDryer_UseInv() function and add thecommand in bold to it.
function hDryer_UseInv()
{if (player.ActiveInventory == inventory[3]) {SetBackgroundFrame(1);object[0].Visible = true;cDave.Say("It's my iPod");cDave.Say("How did that get in there");
}}
This will make the iPod visible when the background frame changes after Dave uses thecredit card on the dryer door. A couple of messages have also been added.
Unit 10 Game Development 2 Page 41 of 71
Interacting with the iPod
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
41/71
Interacting with the iPod
To achieve this we will create a new room with a blank background and only an iPod object.
Create a new room called iPod (this should be Room 4)
Choose blank.bmp as the background.
Change the ShowPlayerCharacter property to False.
When Dave interacts with the iPod he is provided with a close up view of the iPod screen.
On the screen is a message saying Click to Play. Clicking on the iPod screen plays amovie.
When we switch to the room we will not be able to see Dave. This allows us to create theeffect of a close-up view of objects.
Import the sprite for the iPod
Open the Sprites node and import the image iPod.png from the backgrounds folder. Changethe resolution to 640x480. This will be used for the object in the room.
Add the iPod object to the room
Go to the editor for the iPod room and select objects from the dropdown.
Add a new object to the room.
Choose the iPod sprite imported in the previous step to representthe object.
Give it the name oiPodLarge and description iPodLarge todistinguish it from the smaller iPod object in the Laundry Room
Position the iPod in the room as shown below. Take notice of the yellow box. It is this whichyou use to position the iPod It should be equally spaced from left to right and close to the
Unit 10 Game Development 2 Page 42 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
42/71
Now we need to setup an interaction so that when Dave interacts with the iPod in the laundryroom he is taken to Room 4 showing the iPod.
Open the laundry room, choose objects from the dropdown and click on the iPod in the Dryerto select it.
Open the events panel for the iPod and select Interact object.
Add the following script
function oIpod_Interact()
{
cDave.ChangeRoom(4);
}
Notice we do not provide x and y coordinates as Dave will not be visible in the room.
Test your game. When Dave interacts with the iPod inside the dryer, room 4 should openshowing the close-up view of the iPod. Dave should not be visible.
Unit 10 Game Development 2 Page 43 of 71
Pl i id fil
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
43/71
Playing video files
AGS can play any video files that are supported by Windows Media Player. You will need to
make sure the video plays in media player before you use it with AGS.
Open Room 4 and select Objects.
Select the iPod object and open the events.
Select the Any click on object event.
Add the following script to the function
function oiPodLarge_AnyClick()
{
PlayVideo ("dog.avi", 1, 1);
Wait(16);cDave.ChangeRoom(3,219,136);
}
Playvideo
The PlayVideo command requires 3 parametersPlayVideo(NameOfVideoFile, skip, flags)
dog.avi = name of video file to play
Skip defines how the player can skip the video. Options are
player can't skip video player can press ESC to skip video
player can press any key to skip video
player can press any key or click mouse to skip
Flags defines how the video will be played. Options are
player can't skip video
player can press ESC to skip video
player can press any key to skip video player can press any key or click mouse to skip
Unit 10 Game Development 2 Page 44 of 71
Once the video has finished playing there will be a slight wait period and then Dave will
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
44/71
Once the video has finished playing there will be a slight wait period and then Dave willbe returned to the laundry room.
Note that for completeness of this tutorial game, you should really add the iPod to the
Inventory, and set it so that when you interact with the iPod whilst in the Inventory it replaysthe dog.avi video.
There are some other more significant problems however.
Firstly, when Dave changes rooms, the room functions run again. Therefore, the backgroundof the room is restored to background[0] with the Dryer door closed.
Secondly, if we want other scripts to run once Dave re-enters the room (for example, wewant Dave to say some messages once the video has finished), we cannot add thesecommands in the room 4 script because they will only apply to the current room (room 4).
To overcome these problems we will need to use some global variables.
Global variables are variables that can be used in any script in any room.
Declaring Global Variables
Before you can use a global variable it must be declared in the global script.
Open the scripts node in the Project Tree and double-click GlobalScript.asc.
There will already be a significant amount of code in there already as part of the default game
template. Add the following lines
int playvid = 0; creates a variable called playvid and initialises its starting value to 0;
export playvid; allows the variable to be imported into other scripts
Reopen the script for room 4At the very top of the script add
import int playvid;
Unit 10 Game Development 2 Page 45 of 71
Wait(16);
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
45/71
cDave.ChangeRoom(3,219,136);
}
This sets theplayvid variable value to 1
Open the script for the laundry roomAt the very top of the script also add
import int playvid;
Find the room_AfteFadeIn() function and add the following shown in bold.
function room_AfterFadeIn()
{
if (playvid==1) {
SetBackgroundFrame(1);object[0].Visible = true;
Wait(16);
cDave.Say("Wow, that was a strange movie");
cDave.Say("Who is the Baron?");
cDave.Say("..and why do I have to go to the general store?");}
SetBackgroundFrame(0);
}
This is the function that runs after the room has faded in. Previously it was being used to setthe background image to the first background.
We use an IF statement to check the value of playvid first. If it equals 1, meaning that thevideo has been watched then we can set the background to the 2nd image, make sure theiPod is visible and have Dave say a couple of messages.
Note that for completeness of this tutorial game, you could also add the iPod to the Inventory,and set it so that when you interact with the iPod whilst in the Inventory it replays the dog.avivideo.
Unit 10 Game Development 2 Page 46 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
46/71
Room 5: Downstairs an encounter with the Baron
We will now create Room 5. Room 5 is Daves lounge room. It is here that he first meets theBaron and engages in a conversation.
Create a new Room with the description Lounge Room.
Import the image DavesLounge.bmp
Create some walkable areas as well as a walk-behind for when Dave is walking down thestairs. (Dont forget the baseline for the walkbehinds)
Walkable areas Walk-behinds
Open the characters node in the Project Tree and double-click on cBaron to open hisproperties.
Set his starting Room to 5, his x location to 41 and his y location to 165.
Also change Daves starting room to room 2.
This will allow you to easily test your game without having to navigate all the other rooms.
Unit 10 Game Development 2 Page 47 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
47/71
Changing Rooms
Dave needs to be able to access the Lounge room from the hallway. Therefore we need tocreate an event that allows Dave to leave Room 2 (hallway) and enter Room 5 (LoungeRoom)
Open Room 2 the hallway
Dave will change to the Lounge room when he leaves the screen on the left i.e. he has
walked down the stairs.
We can manually define where the edges of the room are located.
Open the drop down for the room and choose edges
You will notice that there are 4 yellow lines that define the rooms edges.
Hold the cursor over the left edge until it turns into a double-arrow and drag the yellow line tothe right as shown below.
Open the Rooms events and select .
Unit 10 Game Development 2 Page 48 of 71
function room_LeaveLeft()
{
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
48/71
{
cDave.ChangeRoom(5,270,55);
}
Test your game and enter the Lounge Room.Unfortunately the Baron is facing in the wrong direction.
In the enters room before fade-in event for the lounge room add thefollowing script
function room_Load()
{
cBaron.FaceCharacter(cDave);
}
This script will make the Baron (cBaron) face (FaceCharacter) Dave (cDave).
OK, we now have characters, rooms, transitions, videos, inventory sorted. So on to one of the
major components of adventure games, the dialogue between characters.
Unit 10 Game Development 2 Page 49 of 71
PART 4 Time for a ChatPART 4 Time for a Chat
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
49/71
Conversations
A conversation in AGS allows the player to choose from a list of topics to talk about.
Creating a DialogOpen the dialogs node in the Project tree.Double-Click on the available default dialog and change its name todBaronTalk.
Add the following responses in the Topic boxes. These are all the options that Dave canchoose from. If they have a tick beside Show then the text will be displayed when the dialogfirst runs.
Dialog Script
Topics
When the player selects one of the options from a topic the topics dialog script is run. Forexample, if the player chooses Topic 1: What are you doing in my house?then @1 in thescript will be run.
Currently all scripts are blank.
The @s entry point defines what happens when the dialog is first started. When Dave firststarts the conversation with the Baron we want him to say Hello, who are you and what are
Unit 10 Game Development 2 Page 50 of 71
Important: Note that in dialog script we do not put the c in front of the charactersname Therefore cDave becomes Dave
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
50/71
name. Therefore cDave becomes Dave.
@S // Dialog startup entry point
Dave: Hello, who are you and what are you doing in my house?Baron: I am the Baron
return
@1
Before we go test our game to see how this works, we need to invoke the dialog when Davetalks to the Baron.
In the Project Tree open the characters node and double-click on cBaron.
Open his events and select Talk to character
Add the following command to the function
function cBaron_Talk()
{
cDave.Walk(103, 169, eBlock);
cDave.FaceCharacter(cBaron);
dBaronTalk.Start();
}
This will make Dave walk to the Baron and face him before starting the dialog when we use
the talk-to mode on the Baron
Run your game and use the talk-to mode on the Baron
The first thing that will happen is Dave will talk and then the Baron will reply as we definedunder the @s entry point.
Once the Baron has finished the return command signals the end of the @s script and thetopics with the Show option selected are displayed.
If you select one of the options. For example, option 1 What are you doing in my House?then Dave will say the text and @1 will run. Currently we have no script in @1 so nothing willhappen once Dave has spoken.
Unit 10 Game Development 2 Page 51 of 71
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
51/71
The Baron also uses the same speech colour as Dave so we need to change it by opening
cBarons properties and changing the SpeechColour property to another number.
Finding Speech Colours
You can easily find the colour of speech by openingthe Colour node in the Project Tree and eithertyping a number into the Colour Finder and pressingFind Colour and selecting a colour. You canthen type this number into the SpeechColourproperty.
Unit 10 Game Development 2 Page 52 of 71
// Dialog script file@S // Dialog startup entry point
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
52/71
g p y pDave: Hello, who are you and what are you doing in my house?Baron: I am the Baronreturn@1
Baron: I need your help Daveoption-off 1option-off 2option-off 3option-on 4option-on 5option-on 6return@2Baron: What have you heard?Dave: The dog told me to be careful of youBaron: Why would you believe a talking dog?
option-off 2return@3Baron: OK, but be careful Davestopreturn@4Baron: I know a lot of things about you Dave.option-off 4return@5Baron: I hope you'll reconsider some timeBaron Goodbye Davestopreturn@6Baron: On your way to town you will meet a stranger.Baron: You will learn more then.Baron: Remember the number '24'.stopreturn@7return
Add the rest of the script as shown.
option-off turns a topic optionoff so that it will not be displayed
option-on turns a topic on
return returns the dialog to thescript
stop exits the conversation
Run the game and test out the
topics. Follow along with the scriptas you go so that you can see howit works.
There are a number of commandswhich are available inside thedialog script to give the playerinventory items, give points,change rooms, play sounds etc.
We will use one of these to run ascript which makes the baron moveand disappear after theconversation has finished. That is,after a stop command.
At the moment, once the conversation ends Dave is left in the room with the Baron.
We cannot add any commands after the dBaronTalk.Start() command that will run after theconversation has finished. The only way to achieve this is by running a script from the dialogitself.
Before each stop command in the dialog add the following command.
run-script 1
Unit 10 Game Development 2 Page 53 of 71
Open the global script globalscript.asc.
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
53/71
Add the following function to the bottom of the script
function dialog_request (int bpass){if (bpass == 1){
Wait(16);
cBaron.Say("Goodbye Dave");
cBaron.FaceLocation(5, 150);
while (cBaron.Transparency < 100){
cBaron.x-=1;
cBaron.Transparency +=1;
Wait(1);
}StopDialog();
cDave.Say("WOW, that was freaky");
}
}
When the run_script 1 command is run this function will be called and passed the value 1 as
the parameter bpass.
It then checks the value of bpass. If it is a 1 then the Baron says a messagecBaron.Say("Goodbye Dave"), turns around cBaron.FaceLocation(0, 109)and thenbegins to move towards the door disappearing as he goes.
while (cBaron.Transparency < 100){
cBaron.x-=1;cBaron.Transparency +=1;
Wait(1);
}
Once he has disappeared Dave says WOW, that was freaky cDave.Say("WOW, that wasfreaky").
When would you use something like this in your own game? You would use it when youwant the NPC to leave after the dialogue event has completed. If you are happy for the NPCto remain and for the dialogue to be repeated if the player talks to the character, then youwould NOT use this
Unit 10 Game Development 2 Page 54 of 71
PART 5 Let the game do some talking (Intro, Cutscene or Conclusion)PART 5 Let the game do some talking (Intro, Cutscene or Conclusion)
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
54/71
Cutscenes
Now that Dave has the information he needs we can send him off to town. Once Dave leaveshis house he will meet a stranger on the way to town who will give him more clues. We willtake the interaction away from the player here and create a cutscene.
You could use a cutscene in your game either during the game to supply information whichdoes not require any player interaction, or alternatively at the start to provide an introductionto the game, or at the end to conclude the game.
IMPORTANT: If / when you use a cutscene as the ending for your game, make it very verygood. It is after all the concluding finale, and the final reward to the player for having investedtheir time in playing the game. There is nothing worse than being let down by a crappy finalending cutscene.
A cutscene is basically a sequence of actions over which the player has no control.
Create a new room and import the background streetwalk.bmp
Create some walkable areas
Unit 10 Game Development 2 Page 55 of 71
Exiting Room 5 The Living RoomExiting Room 5 The Living Room
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
55/71
Create a hotspot on the living room door and set aWalkToPointCreate a hotspot on the living room door and set aWalkToPoint
Add an event when Dave interacts with the hotspot andtype the following room change command in the function.Add an event when Dave interacts with the hotspot andtype the following room change command in the function.
function hLRoom_Door_Interact()function hLRoom_Door_Interact()
{{
cDave.ChangeRoom(6, 16, 105);cDave.ChangeRoom(6, 16, 105);
}}
Add the script for Room 6 The Streetwalk
Open the editor window for Room 6 and go to the events window.Choose the enter room after fade-in event and add the following script.
function room_AfterFadeIn()
{
cMax.Walk (150,108);
cDave.Walk(170,108, eBlock);cMax.FaceCharacter(cDave);
Wait (5);
cDave.Say("How you doin?");
Wait (2);
cMax.Say("Not too bad, yourself?");
cDave.Say("Been better.");
cDave.Say("My name is Dave");Wait (5);
cMax.Walk (150,118,eBlock);
cMax.FaceLocation(150, 200);
cMax.Say("I know");
cMax.Say("Dave, you are in terrible danger");
Wait (10);cDave.Walk (170,118,eBlock);
Wait (10);
cDave.FaceLocation(170, 200);cDave.Say("What do you mean?");
Wait (10);
cMax.FaceCharacter(cDave);cMax.Say("When you get to town visit the General Store");
Unit 10 Game Development 2 Page 56 of 71
To display a message before the script runs, go to the Events for the Room again and locate
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
56/71
the First Time Enters Room event.
Open the event and add the following to the function.
function room_FirstLoad()
{
Display ("Dave is on the way to town");
}
Unit 10 Game Development 2 Page 57 of 71
Additional Scripting Notes
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
57/71
In AGS, all the interactivity in the game is handled using scripts. They're an essential part ofgame-making, so it's important that we go through how to use them.
The Basics
Right, we'll start off by doing something very simple - displaying a message to the playerwhen they click the Look icon on a hotspot. Assuming that you've done the main AGSTutorial, you should already have created a script that looks like this:
function hDoor_Look(){Display("It's quite a large, ominous looking door.");
}
Let's look at this in detail. "function" tells AGS that this is a block of script code that will runwhen an event occurs. "hDoor_Look" is the name of that event. The empty parentheses ( ) tellAGS that this function takes no parameters (we'll come to them later). Finally, the curly
brackets {and} define where this block of code starts and ends. Anything that you putbetween the { and the } will be run when this event is triggered.
Displayis the name of the built-in command that we're going to run. Then, in parenthesis weput the parametersto that command. Parameters are extra pieces of information that thecommand needs to run -- in this case, it needs the message that we want to display.
Finally, we end the line with a semicolon. You use semicolons to tell AGS that it's the end of
the command. Anything that you put after the semicolon becomes a separate command, andyou'll usually do this on a new line.
It's important to mention here that lines beginning with a double-slash // are comments - AGSwill ignore them, they are just there to help you remember what your script is doing. You canadd comments to your script simply by starting the line with the // symbol.
Commands Explained
Each different command you can use in the script is also called a function. All the availablecommands are listed in the Scripting part of the manual, which also tells you how to use them.
Unit 10 Game Development 2 Page 58 of 71
The key point here is the part of the first line inside the brackets. This is called the parameterli t d d fi h t t i t th f ti A t i i f ti
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
58/71
list and defines what parameters you give to the function. A parameter is some informationthat the function uses to decide what to do.
Each parameter is listed, separated by commas. They can be one of the following:
string nameThis parameter is a string, ie. a piece of text. This means that for this parameter yousupply text, surrounded by double-quotes. For example, "My text" .nameis the name by which the parameter is referred to in the function description, it isnot relevant for writing your script.
int name
This parameter is an integer, ie. a numerical value. This means that for this parameteryou supply a number, for example 65 .
CHARIDThis parameter is a character script name. You need to supply the script name of oneof the game characters.
InventoryItem*This parameter is an inventory item. You need to supply the inventory item you want touse.
...This parameter is optional, and can be of any type. You do not have to supply it at all,but if you do the function description will tell you what type of value to use.
So, we know that our Display function needs a string and an optional parameter. Thedescription goes on to explain that the optional parameter is used for advanced things likedisplaying variable values, so we can ignore it for now.
To make our script call the function we write its name, then the parameters inside brackets,and finally a semicolon. This is very important, as without the semicolon the script won'tcompile. Also, note that we DO NOT write the parameter type (eg. "string" or "int"). So, wecan add this line to our script:
Display("It's quite a large, ominous looking door.");
This is what we already did in the main tutorial, but having examined it in more detail it shouldnow make more sense why we've done it this way.
Instances
Unit 10 Game Development 2 Page 59 of 71
The name by which you access an instance in the script is given in the editor as theitem's Script Name. For example, assuming our main character's script name is cEgo, thenhis instance name will be cEgo
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
59/71
his instance name will be cEgo .
To perform a command on something, you type its Script Name followed by a dot, followed bythe command name. When you type the dot, the AGS Editor will automatically pop up a list ofthe available commands:
The script editor's auto-complete
You then choose the appropriate command, and place any parameters in brackets, like wedid above with the Display command. For example:
cEgo.AddInventory(iKey);
This will add the Key to the EGO character's inventory. If you look up AddInventoryin themanual, you'll find it takes two parameters, an InventoryItem * and an optional int. TheInventoryItem*means that you need to supply the Script Name of the inventory item; this issomething you can set in the script editor.The optional intmeans that there is an extra parameter which you can supply if you want to,
but you don't have to. In this case it allows you to specify where in the character's inventorylist the new item should be added, but we're not concerned with that right now.
As well as all the individual character instances such as cEgo, there is a special instancecalled player. This always corresponds to the current player character, so if you just want toperform a command on the player character (especially useful in games where the player cancontrol different characters) then you can use the playerinstance to do so.
Command Sequences
Suppose we want the player to be given a pink poster when they look at the hotspot, as wellas displa ing the message Ass ming e ha e an in entor item set p to be the poster ith
Unit 10 Game Development 2 Page 60 of 71
Note that the script system is case sensitive, so writing for example addinventory(iposter);will not work
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
60/71
will not work.
The script commands are processed from top to bottom in the order that you write them, sowriting something like:
Display("Why did the chicken cross the road?");Display("Because he was bored.");
will mean that the player gets the two messages in the order you specified.
Recap
So, did you remember these vital points:
Strings are surrounded by double-quote marks. Semicolon after the closing bracket on each line. The script is case sensitive. To use an instance-based command, type the Script Name followed by a dot, followed
by the command name. The playerinstance corresponds to the current player character.
Variables
Scripts in AGS can use variables. A variable is an area of memory storage that contains avalue, which you can check and change with your script.
To declare a variable, you write the variable type, followed by the variable name, then asemicolon. The type is either "int", "String" (note the capital S) or "float", and the name can beanything you like - it is what you will use to refer to it later. For example:
int myCounter;
The variable name can only contain letters A-Z, a-z and the underscore _ character.
You need to declare a variable before you can use it so that the compiler can spot any
Unit 10 Game Development 2 Page 61 of 71
Variable Scope
An unfortunate side effect of the script's attempt to emulate the 'C' language is variable scope
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
61/71
An unfortunate side effect of the script s attempt to emulate the C language is variable scope.In short, this means that you need to place your variable definitions OUTSIDE all the event
handlers, otherwise their values will keep getting reset.
So, to declare a variable for use by one of the room interaction scripts, you need to place thedefinition above the main function body. So, it should look something like this:
// room script fileint myCounter;
(other event scripts)
function hDoor_Look(){
Display("It's quite a large, ominous looking door.");}
(rest of file follows)
No script commands can be used outside functions (or AGS wouldn't know when to runthem!) - only variable declarations are allowed there.
Changing variables
You can change the value of a variable very easily in the script - simply write the variable
name, the equals sign, then the new value, followed by the semicolon. So:
myCounter = 10;
will change the value of our variable to be 10.
You can add to and subtract from a variable using the += and -= operators. So, to add 3 tothe current value of myCounter, do the following:
myCounter += 3;
Checking variables
Unit 10 Game Development 2 Page 62 of 71
what this means is that if myCountercontains the value 5, then the script inside the { }brackets will be run (which in this case changes the value of myCounter to zero).
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
62/71
brackets will be run (which in this case changes the value of myCounterto zero).If myCounterdoes not equal 5, the script inside the brackets is not run and execution carries
on from after the } .
Note the double-equals in the if statement. In an "if" statement, you ALWAYS use thedouble-equals operator, which compares the two values. If you used a single equals it wouldset the value instead, which will yield some strange results.
The == is called an operator, because it performs an operation on the two values. Thefollowing basic operators are available:
==compares the two values, and proceeds if they are the same.
!=compares the two values, and proceeds if they are not the same.
compares the two values, and proceeds if the left hand value is bigger than the righthand value.
=proceeds if the left hand value is equal to or bigger than the right hand value
Putting it into practice
Now let's do something useful with our variable. Suppose that we want to have differentmessages every time the player looks at the hotspot. So, the first time they look it willdescribe it, then if they look again they get a different message describing something in moredetail. Our code will want to look something like this:
if (myCounter == 0){Display("You see a bookshelf.");
}if (myCounter == 1)
Unit 10 Game Development 2 Page 63 of 71
{Display("There is nothing else of interest on the shelf.");
}
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
63/71
}if (myCounter < 3)
{ myCounter += 1;}
myCounterstarts off set to 0, so the first time this script is called it will run the first Displaycommand, but not the others. Then, since 0 is less than 3, it will increase myCounterby 1,and since 0+1 = 1 it now holds the value 1.Once the player has seen all the messages (myCounter== 3), it no longer increases the
value so if they click again they will keep getting the final message.
Global variables made easy
Sometimes, you may want to set a variable value that can be shared between a room scriptand your global script. There are two ways to do this -- you can export the variable from theglobal script and then import it in the script header, but that's a bit advanced for this tutorial. Asimpler way is to use one of the 300 GlobalInts, which use the script functions SetGlobalIntand GetGlobalInt to access them. See their manual descriptions for more information.
Functions that return a value
When reading function descriptions in the manual, you will notice that some of them say theyreturn a value. For example,
IsGamePaused ()Returns 1 if the game is currently paused, or 0 otherwise.
You use these much as you would use a literal value such as "9". For example, you can do:
// Put the return value into our variablemyCounter = IsGamePaused();
(OR)
// Test the return value directlyif (IsGamePaused() 0)
Unit 10 Game Development 2 Page 64 of 71
Common Shortcuts
The script system has a few nice shortcuts for common tasks which you will find yourself
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
64/71
p y y yusing regularly.
Firstly, the ++ and -- operators increase and decrease the variable by 1, respectively. So, thelast part of our previous script could have been written:
if (myCounter < 3){myCounter++;
}
Also, the { } brackets are only needed if you are using more than one command inside them.Since we have only one command, the "my_counter++;" line, we can remove the { }completely and just be left with:
if (myCounter < 3)myCounter++;
However, this can lead to mistakes in scripts that are hard to spot, so I would advise alwaysusing brackets just to be safe.
Finally, if you want to test whether a value is zero or not, you can just write it as follows:
if (myCounter)Display("counter is non-zero");
which is equivalent to:
if (myCounter != 0)Display("counter is non-zero");
LoopsYou may find it useful to have a sequence of commands that are executed more than once.AGS supports this, using the whilekeyword. Its format is virtually identical to if:
Unit 10 Game Development 2 Page 65 of 71
NOTE: be careful with while loops - it is possible to crash your game by using a badlywritten one. Consider this:
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
65/71
int counter = 1;
while (counter > 0) {counter ++;}
Here, counterstarts off as 1, so the loop will run. Then, it will increase to 2. Since it is stillgreater than 0, the loop will run again. This particular loop will run forever, since countercannever become less than 1, and your game will grind to a halt.
Multiple conditions
On several occasions, you don't just want to decide what to do based on one variable - theremay be a combination of things you want to consider.For example, suppose that you want to display a message if the player has two specificinventory items. You could do this, and put two ifstatements inside each other:
if (player.HasInventory(iFirstItem)){if (player.HasInventory(iSecondItem)){Display ("You have both the items!");
}}
However, this is quite unwieldy and if you have a lot of conditions it will look rather messy. So,AGS lets you do it this way:
if ((player.HasInventory(iFirstItem)) &&(player.HasInventory(iSecondItem)) )
{Display ("You have both the items!");
}
This makes use of the && operator. Note that you need an extra pair of outer parenthesis, tocontain the whole expression. Each part of the expression goes inside parenthesis, as
l d th j i d ith th && b l
Unit 10 Game Development 2 Page 66 of 71
Display ("It's all working out fine.");}
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
66/71
'OR' expressions
Sometimes you will want to do some processing if one or another condition is true. Forexample, you might want to let the player open a door if he has either the door key or achainsaw.
if ((player.HasInventory(iDoorKey)) ||(player.HasInventory(iChainsaw)) )
{
player.ChangeRoom(10);}
The operator here is the double-vertical-bar || operator. It works similarly to the && operator,but it will process the commands inside it if either one expression, or the other, or both, aretrue.
Doing one thing or another
Sometimes, you want the script to take one course of action if a variable is set, and anothercourse of action if it isn't. Initially, you might think you would do this:
if (timer == 5) {// do something
}if (timer != 5) {// do something else}
That would work -- however, there is a neater way, using the else keyword:
if (timer == 5) {// do something}else {// do something else
Unit 10 Game Development 2 Page 67 of 71
if (timer == 5) {// do something}
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
67/71
else if (timer == 6) {
// do something different}else {// do this if it's not 5 or 6
}
Your Own Functions
You've probably noticed in the manual, it mentioning functions such as repeatedly_execute,and on_event, and how you can add them to your global script to do cool stuff. But you maybe wondering, how exactly to go about it.
Remember in tutorial 1, we learnt about function parameters and how they could be int,string, etc. Well, you write your own functions like this:
function dialog_request(int param){// contents of function go here}
You start with the keyword function, then follow it by the function name, and then parenthesislisting the parameter types and names. For each parameter that you want, you need to write
its type (intor string), followed by the name it will be known by inside the function. This namecan be anything you like - it is similar to naming a variable.
There are some fixed functions, such as dialog_request and on_event, which are part of AGSand therefore you MUST use the correct number and type of parameters. However, you mayalso add your own functions by naming them however you like, and having as manyparameters as you need.
Functions are useful if you have a block of script code that you need to use in two differentplaces - putting it in a function instead means you don't have to copy & paste, and that if youmodify it, all other script that relies on it gets updated too.
To call your function from elsewhere in the script just do it exactly like you call a built-in
Unit 10 Game Development 2 Page 68 of 71
if (data == 5){aSpecialScoreSound.Play();
}
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
68/71
}
Display("You just got %d points!", data);}}
With this script, whenever the player scores points, they will get a message telling them so.Also, if they happen to get 5 points at once, it will play audio clip aSpecialScoreSound.
As you can see, you use the function parameters just like any other script variables.
Our own function
Now, suppose we have a special animation of the player doing a dance, and we want to beable to play it from various points in the script. By far the easiest way to do this would be toput it in a function:
function do_dance(){
cEgo.LockView(10);cEgo.Animate(2, 5);cEgo.UnlockView();
}
This function runs view 10, loop 2, as the character's animation, waits until it finishes and then
reverts to the default view.
TIP: If you're wondering where to place your custom functions, just open up the global script(Game menu, Edit Global Script) and write them in there. The function must be outside allother functions.
Now, elsewhere in your script, when you want the player to dance, just do:
do_dance();
Returning a value
Y h i d h f h b il i f i h I G P d
Unit 10 Game Development 2 Page 69 of 71
}
This function adds the two numbers together and returns the result (a useless function in
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
69/71
practice since the + operator does the same thing, but it demonstrates the point).
Another part of your script could then do:
total = add(5, 10);
for example.
Using functions from room scripts
You may notice that when you add your own function to your global script, you can call it finefrom other places in the global script but attempting to use it in a room script gives a parseerror. The manual explains how to solve this using the script header.
Unit 10 Game Development 2 Page 70 of 71
Conclusion
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
70/71
That essentially covers the key skills that you will require for the development of your game inthis Unit. There are other areas that you can refine the look at feel of your game, and Iencourage you to check out the other tutorial document Getting Started with AGS ver3.0.1.doc
Of particular interest, check out the available templates which you may feel better suit the GUIfor your game. There are several available including ones which duplicate the Monkey Island
interface.
Before you get started on your own game, there are now several steps which you mustundertake.
1. Creating your teams complete game script2. Overlaying backgrounds in Excel for pixel referencing3. Fleshing out full dialogue trees
These should be jobs that you allocated to individual members of the team.
Finally, for an additional resource on creating your first AGS game, refer to the documentGetting Started with AGS ver 3.0.1.doc. (in the same folder as this document). It wascreated from the built in tutorial that comes with AGS and covers the same concepts but fromthe perspective of the original developer of Adventure Game Studio, as well as other areas
like using different cursors and different fonts.
Unit 10 Game Development 2 Page 71 of 71
Programming CODE Summary
-
8/2/2019 1. Unit 10 AGS Tutorial 2303cy5
71/71
WHAT ACTION TUTORIAL GAME EXAMPLE GENERIC CODING REQUIREDFace a location cDave.FaceLocation(211, 53); Character.FaceLocation(x,y);
Face a character cBaron.FaceCharacter(cDave); Character.FaceCharacter(Character);
Change Speech colour cDave.SpeechColor = 10; Character.SpeechColor = 10;
Set speech style SetSpeechStyle(eSpeechSierra); SetSpeechStyle(speechstyle);
Display a message Display("It's a picture of James Hetfield from Metallica"); Display("message");
Make a character talk cDave.Say("I Love this picture"); Character.Say("message");
Change room cDave.ChangeRoom(2,211,145); Character.ChangeRoom(Room,x,y);
Pick up an inventory item oCreditCard.Visible = false;cDave.AddInventory(iCard);
oCreditCard.Visible = false;Character.AddInventory(iCard);
Walk to a location cDave.Walk(180, 140, eBlock); Character.Walk(x, y, eBlock);
Set a pause Wait(40); Wait(40);
Change the background SetBackgroundFrame(0); SetBackgroundFrame(#);
Check if player has used aninventory item
if (player.ActiveInventory == inventory[3]){
SetBackgroundFrame(1);
}
if (player.ActiveInventory == inventory[#]){
SetBackgroundFrame(#);
}Play a video PlayVideo ("dog.avi", 1, 1); PlayVideo ("video", 1, 1);
Using variables
int playvid = 0; (GLOBAL)export playvid; (GLOBAL)import playvid; (ROOM)playvid = 1; (INTERACTION);
int playvid = 0;export playvid;import playvid;
playvid = 1;
Start a dialog dBaronTalk.Start(); Dialog Name.Start();
Run a script run-script 1 run-script 1
Run global scriptdialog_request
function dialog_request (int bpass){
if (bpass == 1){} }
function dialog_request (int parameter){
if (parameter == 1){.
} }
Run a loop
while (cBaron.Transparency < 100){cBaron.x-=1;cBaron.Transparency +=1;Wait(#);
}
while (character.Transparency < 100){character.x -=1;character.Transparency +=1;Wait(#);
}
First AGS Game Tutorial Using Default Game template