Adventure Maker   
   Adventure Maker v4.5 Help Document  
Home (Adventure Maker website)

 

   
Help Contents

Search

Introduction
   Program Overview
   List of Features
   What's New

Creating software without scripting
   Getting Started Tutorials
   Some Techniques and Tips
   Creating puzzles without scripting

   Creating third person games
   Creating interactive 360-degree panoramas
   Creating software for
PSP
   Creating software for iPhone and iPod touch

Creating software with VBScript
(Full Edition only)

   Introduction to VBScript
   Language Reference
   Objects Reference
   VBScript Techniques and Tips

   Sample Source Code

Pictures, sounds and music
   => Creating Pictures
   Music Maker help
   Creative Painter quick help
   Sounds and Music
   Videos, Icons, Cursors

Plugins (Full Edition only)
   Overview of the Plugins System
   Downloading/Uploading Plugins
   The Plugin Properties window
   About the Flash Plugin

Tips
   User Interface Tips
   Reducing the project size
   End-User System Requirements

Advanced tutorials
(Full Edition only)

   Creating a custom startup menu
   Using ActiveX components (ocx)

Troubleshooting
   Common issues and solutions
   Known bugs and limitations

About us
   Credits
   Website
   Contacting us
   Helping out

"iPhone" and "iPod" are trademarks or registered trademarks of Apple Inc. "PSP" is a trademark of Sony Computer Entertainment Inc. All other trademarks are the property of their respective owners.

As of the release date of this version, Adventure Maker is NOT affiliated with, endorsed by, or sponsored by Apple Inc., Sony Corporation, SCEI, or any Apple or Sony subsidiary.

   

 

VBSCRIPT TECHNIQUES AND TIPS (FULL EDITION ONLY, WINDOWS ONLY)

This page contains sample source code that you can use in your projects.

More sample source code is available in the games included in the Adventure Maker package (Othello, Slider Puzzle, Memory Game...). Click here for more info.


1. How to launch an executable at run-time?
2. How to create a random variable?
3. How to go to a random frame each time that the user clicks on a hotspot?
4. How to hide the mouse pointer?
5. How to create a money variable, to increase it and to display it?
6. How to display a 2-lines message?
7. Is it possible to completely change the contents of the inventory when the player comes to another scene?
8. How to display a message in a frame instead of in a standard message box?
9. How to limit the number of inventory items carried?
10. How to change the picture associated with a hotspot?
11. How to move and resize a hotspot during runtime?
12. How to include web links?
13. How to display the LoadGame or SaveGame windows when entering a frame?
14. How to make a looping video appear and disappear every 7 seconds?
15. How to make a bird fly only from time to time (i.e. every X seconds, where X is a random duration?
16. How to create a score-system?
17. How to make the score appear on all the frames?
18. How to password-protect a part of the game?
19. How to create a global countdown?
20. How to completely replace the drop-down menu that appears when pressing Esc?

21. How to display the frame name on all the frames?
22. How to display the current time on all the frames?
23. I have a Dialogue and when it end I want it to go to a new frame. How can I do that?
24. How to allow the player to examine the inventory items?
25. Can I create recursive timed events?
26. How many timed events can I create?
27. In the dialogue wizard, how to make it so that the message won't disappear until you click on it?
28. How to go to another frame only after the player has clicked 5 times on a hotspot?
29. How to play sounds and/or videos from within VBScript?
30. How to determine if the player has a specific item in the inventory?
31. How to show/hide an item that is already in the inventory?

 

1. How to launch an executable at run-time?

Just use one of the two following commands: "Action.OpenFile" and "Action.OpenExeFileAndWait". The difference between the two commands is that the second one will wait for the end-user to close the exe before continuing. For more help on how to use those two functions, go to the Language Reference.

 

2. How to create a random variable?

First you need to create a new variable. To do so, click the "Variables..." button that is under the VBScript text field in the "Hotspot Properties" window, and then click "New Integer Variable...".

To assign randomly the value 0 or 1 to an integer variable, use the following code:
randomize
myvariable = int(rnd*2)

where "myvariable" is the name of your integer variable. Use this code in conjunction with the functions that are under the "Variables" tab in the "Hotspot Properties" to enable or disable (as well as to show or hide) a hotspot randomly.

If you wish to assign a random value (other than just 0 and 1) to an integer variable, use the following code:
randomize
myvariable = int(rnd*(MAXVALUE-MINVALUE+1))+MINVALUE

where "myvariable" is the name of your integer variable, and MINVALUE and MAXVALUE are the minimum and the maximum values that the variable can have. For example, to get a random value between 0 and 100, you should replace MINVALUE with 0 and MAXVALUE with 100.

 

3. How to go to a RANDOM frame each time that the user clicks on a hotspot?

Go to the "Hotspot Properties" of that hotspot, click the "Advanced" tab, check the option "Execute VBScript code", and then enter the following code in the text field:
   randomize
   i = int( RND * 4 ) + 1
   if i = 1 then action.GoToFrame "Frame1"
   if i = 2 then action.GoToFrame "Frame2"
   if i = 3 then action.GoToFrame "Frame3"

   if i = 4 then action.GoToFrame "Frame4"

where you must replace Frame1, Frame2, etc. with the name of your frames. If you want to use more than 4 frames, you must change the number 4 that is in the first line of code.

 

4. How to hide the mouse pointer?

First make sure that the file "Invisible.ico" is in the "Icons" sub-folder of your project folder (if it is not there, import the one that is in "Icons" sub-folder of the Adventure Maker folder).
Then use the following code:

   Action.ChangeDefaultCursor "Invisible.ico"
To restore the default pointer, use the following code:
   Action.ChangeDefaultCursor ""

 

5. How to create a money variable, to increase it and to display it?

Just create an "integer" variable called for example Money, and then use the following code to increase it:
   Money = Money + 1

To display it on the screen, create a new textbox (by right-clicking on the frame background), and then use the following code:
   Text(1) = Money

 

6. How to display a 2-lines message?

To display a 2-lines message you can use the following code:
Action.Message "Line1" + VbCrLf + "Line2"

where you can replace "Line1" and "Line2" with the text that suits your needs.

 

7. Is it possible to completely change the contents of the inventory when the player comes to another scene?

Yes, you just have to use the following commands: Action.RemoveAllItems, Action.RemoveItem and Action.AddItem. Those commands are described in the Language Reference page.

 

8. How to display a message in a frame instead of in a standard message box?

Here is a complete step-by-step tutorial for creating a new function called "DisplayCustomMessageBox" that will display a message in a frame instead of in a standard message box.


1. Create a new global variant variable called "MyMessage".

2. Add the following code to the VBScript Global Procedures:

Sub DisplayCustomMessageBox(msg)
  MyMessage = msg
  GoToFrame "MessageBoxFrame"
End Sub


3. Create a new frame called "MessageBoxFrame"

4. Create a new text into it by right-clicking on the frame background (enter any text).

5. Go to the Frame Properties enter the following code under the "Advanced" tab:

Text(1) = MyMessage

6. Go to the Frame Properties and check the option "Enable Timed" under the "General" tab. Enter the duration of the message (like 5 seconds) and choose "[LAST VISITED FRAME]" under "Destination Frame". Note: if you wish to add a button for closing the message instead of using a timer, just create a hotspot that is linked to the "[LAST VISITED FRAME]".

That's all. When you want to display your custom message, just use the following code:
DisplayCustomMessageBox "This is my message!"

 

9. How to limit the number of inventory items carried?

- If you simply want to prevent the player from being able to pick up several copies of the same item, go to the Hotspot Properties of the hotspot that allows you to pick up an item, and check the option named "Hide and disable this hotspot (permanently)" that is under the "Options" tab.

- Otherwise, if you want to limit the TOTAL number of items carried at a time, create an Integer variable (click "Project Variables"->"New Integer Variable") called for example VAR1; increase it by 1 each time that an item is picked up, and then prevent the items from being picked up when VAR1 > N (where you must replace N with the maximum number of items that can be carried). To do so, go to the Hotspot Properties of the hotspot that allows to pick up an item, and add the following VBScript code:
   If VAR1 < N Then
      Action.AddItem "ITEM_NAME"
      VAR1 = VAR1 + 1
   Else
      Mesage "You cannot carry more than N items."
   End If

(where you must replace ITEM_NAME with the name of the item to be picked up, and N with the maximum number of items allowed).

 

10. How to change the picture associated with a hotspot?

- To change the picture during editing, simply go to the Hotspot Properties (by right-clicking on the hotspot and then clicking "Properties"), then select "Picture" under "Hotspot Appearance", and then select a file.

- To change the picture during runtime, use the following code:
Action.LoadAPicture Hotspot(NUMBER), "FILENAME"

where NUMBER is the number that identifies the hotspot into which you want to load the graphic file, and FILENAME is the name of the graphic file. The graphic file must be located inside the "Hotspot Graphic Files" sub-folder of the "Project Resources", which corresponds to the directory "c:\...\PROJECTNAME\Areas". The supported graphic types are: BMP, JPG, GIF (not animated), WMF, EMF, ICO and CUR.

Note: if you want to remove the hotspot picture (i.e. to make the hotspot become transparent), replace FILENAME with an empty string, as shown below:
Action.LoadAPicture Hotspot(NUMBER), ""

 

11. How to move and resize a hotspot during runtime?

To move and resize a hotspot, just use the following code:
Hotspot(NUMBER).Move X*15,Y*15,WIDTH*15,HEIGHT*15

where NUMBER is the number that identifies the hotspot that you want to move, and X,Y,WIDTH and HEIGHT are the new coordinates and size of the hotspot in pixels. Notice that the values are multiplied by 15, in order to convert them from pixels to twips.

 

12. How to include web links?

Just use the "OpenURL" command. Here is an example:

Action.OpenURL "www.adventuremaker.com"

 

13. How to display the LoadGame or SaveGame windows when entering a frame?

Since the PopupLoadGame and PopupSaveGame commands cannot be executed directly from the "Frame Properties" window, you must use them in conjunction witin the CreateTimedEvent function.

In other words, just add the following code to the "Advanced" tab of the "Frame Properties" window:

CreateTimedEvent 0.1, "PopupLoadGame"
or
CreateTimedEvent 0.1, "PopupSaveGame"

which means that the commands are executed 100 milliseconds after that the frame is loaded.

 

14. How to make a looping video appear and disappear every 7 seconds?

Just create a new global Integer variables (called for example VAR1), and set the looping video to be visible only if VAR1=1 (to do so, change the appropriate settings under the "Variables" tab of the "Hotspot Properties" of the hotspot that corresponds to the looping video).

Then go to the "Frame Properties" of the frame that contains the looping video, enable the option that is under the "Advanced" tab, and then add the following code to the VBScript text field:
Action.CreateTimedEvent 7, "VAR1 = 1-VAR1", True

For help on how the "CreateTimedEvent" function works, refer to the VBScript Language Reference page.

 

15. How to make a bird fly only from time to time (i.e. every X seconds, where X is a random duration)?

1. First you must create a video file with the bird flying. Let's call the video file "bird.avi".
2. Then create a new global Integer variable, called for example VAR1.
3. Then go to the frame where you want the bird to fly from time to time, and create a new hotspot.
4. In the "Hotspot Properties" window, select "looping video" under the section "Hotspot appearance".
5. Click "click here to select a file", and import the file "bird.avi".
Do not close the Hotspot Properties window yet.
6. Change the "Number of loops" setting to 1 (default is 0).
7. Change the settings that are under the "Variables" tab so that the hotspot is visible only if VAR1=1. Then close the Hotspot Properties window (click OK).
8. Go to the "Frame Properties" of the frame that contains the looping video of the bird, enable the option that is under the "Advanced" tab, and then add the following code to the VBScript text field:

   VAR1=1
   MakeBirdFly

9. Now close the "Frame Properties" window (click OK), and go to the "VBScript Global Procedures" (to do so, click "VBS Procedures" from the menu on the left).

Copy/paste the following code into the large text field:

Sub MakeBirdFly
  VAR1 = 1 - VAR1
  Randomize
  Minimum = 4
  Maximum = 15
  Action.CreateTimedEvent Int(RND*(Maximum - Minimum + 1) + Minimum),"MakeBirdFly"
End Sub

That's all. If everything works fine, you should see a bird flying every X seconds, where X varies between 2*Minimum and 2*Maximum seconds. Note that you can change the "Minimum" and "Maximum" values to suit your needs.

 

16. How to create a "score" system?

First you need to create a new integer variable that will hold the score. To do so, click the "Variables..." button that is under the VBScript text field in the "Hotspot Properties" window and click "New Integer Variable...". Let's call the new variable MYSCORE.

To increase the value of the score by 1, simply use the following code:
MYSCORE = MYSCORE + 1

If you want to tell the player what his or her score is, use the following code:
msgbox MYSCORE

If you want to use a sentence such as "Your score is:", then use the following code:
msgbox "Your score is: " + cstr(MYSCORE)

The reason why the cstr function is used is that you can only add two variables of the same type. Since "Your score is:" is a string and MYSCORE is an integer, you need to convert it to string (with the cstr function) before you can use the "+" operation.

If you want to say "You have not completed the game" if the score is lower than, say, 1000 points, use the following code:
if MYSCORE < 1000 then msgbox "You have not completed the game."

 

17. How to make the score appear on all the frames?

This question assumes that you have already created a variable contains the score (see the previous question), and that the variable is called MYSCORE.

The following steps will show you how to display the value of MYSCORE on all the frames.

1. Create a new frame, called for example MyScoreFrame.
2. Double-click to get to the frame editor.
3. Right-click to create text.
4. Type the text: "score". Position it where you want the score to appear on all the frames. Close the frame.

5. Click the link for Runtime Frames Merging.
6. You must select each frame that you want to merge with the hotspot in the frame. Use <shift> or <ctrl> to select multiples. Next use the pull-down menu to the frame called MyScoreFrame.

7. Now each of the frames will share the text box, but they don't know what to do with it. Open the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code every time that a frame is loaded", and type in the following code:

i = Action.GetMergedTextIndex
Text(i).Caption="Score: "+CStr(MYSCORE)


18. How to password-protect a part of the game? How to ask for a password to enter a room?

1. Simple way:

The following example will show you how to ask the player to enter the password "John" in order to get a hint. Notice that the code below makes use of a local variable called ENTERED_PASSWORD. Variables that are not manually declared using the "Variables" window are local, which means that they are automatically created when the code starts but they are automatically erased at the end of the execution.

ENTERED_PASSWORD = inputbox("To get a hint, please enter the password.")

if ENTERED_PASSWORD = "John" then msgbox "You have entered the right password, (place the hint here)" else msgbox "The password if wrong."

2. More advanced way:

Execute the following code to keep asking for the password until the password is correct or the player has clicked "Cancel":

password = "aj4dm8"
Do
  returnvalue = InputBox("Please enter the password to enter the room.","Password")
  Select Case returnvalue
    Case ""
      MsgBox "You have clicked Cancel"
      Exit Do
    Case password
      MsgBox "Password OK. Entering the room..."
      Action.GoToFrame "DESTINATION_FRAME_GOES_HERE"
      Exit Do
    Case Else
      MsgBox "Wrong password. You will now be asked the password again."
  End select
Loop

 

19. How to create a global countdown?

The tutorial below will guide you through the creation of a global countdown, which for example will be placed at the top-left corner of the screen. We are going to make it so that when the countdown reaches 0, a message will pop up saying "the time is up!".

Of course it will be possible to slightly change the code so that the countdown starts a value different from 20, and so that something else occurs when it reaches 0.

1. Load a project or create a new one.
2. Create a new global Integer variable named "Counter" (without the quotes).
3. Copy/paste the following code into the "VBScript Global Procedures" window:

Sub DecreaseCounter
   If Counter > 0 Then
      Counter = Counter - 1
   ElseIf Counter <> -999 Then
      Msgbox "The time is up!"
      Counter = -999
   End If
   ShowCounter
End Sub


Sub ShowCounter

   text_index = Action.GetMergedTextIndex
   If Counter > 0 Then
      Text(text_index) = Counter
   Else
      Text(text_index) = "Time Is Up"
   End If
End Sub

4. Go to the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code when the project starts or a savegame is loaded", and copy/paste the following code ("20" is the value at which the countdown should start):

If Counter = 0 Then Counter = 20

5. Before closing the Project Properties, check the option "Execute some VBScript code every time that a frame is loaded", and copy/paste the following code:

If Counter > 0 then
   Action.CreateTimedEvent 1,"DecreaseCounter",True
End If
ShowCounter

6. Now close the Project Properties (click OK), then create a new frame named "CountDownFrame" (it doesn't matter what the background is).

7. Edit the frame "CountDownFrame" and add a text object at the top-left corner of the frame (to do so, RIGHT-CLICK at the top-left corner of the frame, enter something in the text field - it doesn't matter what text you enter - and the click OK twice).

8. Now go back to the PROJECT MENU and click "Runtime Frames Merging...". Select all the frames (to do so, you can use the Ctrl or Shift keys), select "CountDownFrame" from the DROP-DOWN menu, and then click "ASSIGN". Then click OK to close the window.



That's all. If everything is ok, when you run your project, you should see a number at the top-left corner of the screen indicating how many seconds are left before the time is up. Furthermore, the status of the countdown is saved in the savegames, and therefore it should work properly even if the player saves and resumes the game.

 

20. How to completely replace the drop-down menu that appears when pressing Esc?

You can replace the default drop-down menu with a custom STATIC menu. To do so, follow these steps:

1. Go to the "Options" tab of the "Project Properties" window and check the option "Remove the drop-down menu at the top of the screen".
2. Create a new frame called for example "MyToolbar".
3. Double-click to edit the frame. Create the buttons that allow to show the "Load Game" and "Save Game" windows, as well as the button to quit the game. To do so, you can use the "PopupLoadGame" and "PopupSaveGame" commands, as explained on the "Language Reference" page. Note that if you have created a custom startup menu (refer to the "
Creating a custom startup menu" page for details), you may prefer to just create a single button on the "MyToolbar" frame, which leads to the custom startup menu frame.
4. Close the "MyToolbar" frame and click "Runtime Frames Merging".
5. Select all the frames from the list on the left (use the Shift or Ctrl keys), then select the "MyToolbar" frame from the drop-down menu on the right, and then click the "Assign" button. Then click OK to close the window.

All the frames of your game will contain the hotspots that you have created inside the "MyToolbar" frame.

 

21. How to display the frame name on all the frames?

The following steps will show you how to automatically display the name of the frame on all the frames.

1. Create a new frame, called for example MyStatusBar.
2. Double-click to get to the frame editor.
3. Right-click to create text.
4. Type some text (like "abc", or anything else, it doesn't matter). Place it where you want the name to appear on all the frames. Close the frame.
5. Click the link for Runtime Frames Merging.
6. You must select each frame that you want to merge with the hotspot in the frame. Use <shift> or <ctrl> to select multiples. Next use the pull-down menu to the frame called MyStatusBar.
7. Now each of the frames will share the text box, but they don't know what to do with it. Open the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code every time that a frame is loaded", and type in the following code:

i = Action.GetMergedTextIndex
Text(i).Caption="The current frame is: "+Action.GetCurrentFrameName

 

22. How to display the current time on all the frames?

The following steps will show you how to automatically display the current time on all the frames.

1. Create a new frame, called for example MyStatusBar.
2. Double-click to get to the frame editor.
3. Right-click to create text.
4. Type some text (like "abc", or anything else, it doesn't matter). Place it where you want the time to appear on all the frames. Close the frame.
5. Click the link for Runtime Frames Merging.
6. You must select each frame that you want to merge with the hotspot in the frame. Use <shift> or <ctrl> to select multiples. Next use the pull-down menu to the frame called MyStatusBar.
7. Now each of the frames will share the text box, but they don't know what to do with it. Open the Project Properties, go to the Advanced tab, check the option "Execute some VBScript code every time that a frame is loaded", and type in the following code:

DisplayTime
Action.CreateTimedEvent 1, "DisplayTime", True

8. Go to the "VBScript Global Procedures" window and add the following code:

Sub DisplayTime
  i = Action.GetMergedTextIndex
  Text(i).Caption = Time
End Sub

 

23. I have a Dialogue and when it ends I want it to go to a new frame. How can I do that?

You must first create a "Thank you, bye bye" (or anything similar) question, with the "Quit the dialogue after this question" option enabled. Then you must go to the "Advanced" tab of the "Question Properties" window and enter the following code:
Action.GoToFrame "FRAME_NAME"
where you must replace FRAME_NAME with the actual destination name.

 

24. How to allow the player to examine the inventory items?

To do that, just create a new "Magnifier Glass" item and use the "Using items on each other" command to go to frames that contain the description of the items.

To go back to the game, use the "go to the last visited frame" command.

Note: if the player has examined several items, the "go to the last visited frame" command will lead to the description of the previous item, instead of leading to the game. To solve the problem, simply disable the inventory while the player is examining an item (in other words, force the player to go back to the game before being able to examine another item). To do so, use the Action.HideInventoryButton and Action.ShowInventoryButton commands.

 

25. Can I create recursive timed events?

Yes, that is possible.

A "recursive timed event" is a timed event (i.e. an object that executes some VBScript code after a given number of seconds) that creates another timed event identical to itselft.

For example, if you wish to display a counter on Frame1 without creating a global variable, you can do the following:

1. Create a new frame called Frame1
2. Create a new Text object on Frame1 (to do so, right-click on the background)
3. Add the following procedure to the "Global VBScript Procedures" window:
Sub IncreaseCounter(X)
 Action.CreateTimedEvent 1, "IncreaseCounter(" & CStr(X+1) & ")"
 Text(1) = X
End Sub

4. Create a new hotspot on Frame1 and set it so that the following code is executed when the hotspot is clicked:
IncreaseCounter(54)
where you can replace 54 with any value of your choice, indicating the initial value of the counter.

 

26. How many timed events can I create?

There are no limitations in the number of timed events that you can create.

For example, instead of using the following code (which stands on a single line and in which there is only one timed event that creates another timed event after 4.5 seconds):
Action.CreateTimedEvent 4.5 , "VAR1=8 : Action.CreateTimedEvent 4.5 , ""Action.Quit"""
you can use the following code (which stands on two lines and in which there are two timed events):
Action.CreateTimedEvent 4.5 , "VAR1=8"
Action.CreateTimedEvent 9 , "Action.Quit"

 

27. In the dialogue wizard, how to make it so that the message won't disappear until you click on it?

There is an easy way to make it so that the message won't disappear until you click on it.

Just add the following code under "After the question has been clicked, do the following", in the Question Properties window (under the "advanced" tab):
CreateTimedEvent 1, "MessageTimerObject.Enabled = False"

BTW, if you want to make the text disappear when the user goes to another frame for example, just execute either
MessageCanvasObject.Visible = False
(this will close only the current question)
or
Action.QuitDialogue
(this will close the whole dialogue)

 

28. How to go to another frame only after the player has clicked 5 times on a hotspot?

Create a new global integer variable. To do so, click "VBS Variables (advanced)" from the Project Menu of Adventure Maker. Let's call it "MyVariable" for example.

Now add the following code to the "advanced" tab of the "Hotspot Properties" window:
MyVariable = MyVariable - 1
If MyVariable = -5 Then Action.GoToFrame "DESTINATION"

Where you must change "DESTINATION" with the name of the frame to which you want to go.

 

29. How to play sounds and/or videos from within VBScript?

All you have to do is to simply copy/paste the following code into the "VBScript Global Procedures" window (click "VBS Procedures" from the Project Menu of Adventure Maker) (you don't need to modify the code):
 

Sub PlayVideo(FileName, Left, Top, Width, Height, Repeat)
  Action.LoadControl MediaPlayerObject(1)
  MediaPlayerObject(1).Move Left*ScreenObject.TwipsPerPixelX, Top*ScreenObject.TwipsPerPixelX, Width*ScreenObject.TwipsPerPixelY, Height*ScreenObject.TwipsPerPixelY
  MediaPlayerObject(1).FileName = FileName
  If Repeat = True Then
    MediaPlayerObject(1).PlayCount = 0
  Else
    MediaPlayerObject(1).PlayCount = 1
  End If
  MediaPlayerObject(1).Visible = True
  MediaPlayerObject(1).Play
End Sub
Sub PlaySound(FileName, Repeat)
  Action.LoadControl MediaPlayerObject(2)
  MediaPlayerObject(2).FileName = FileName
  If Repeat = True Then
    MediaPlayerObject(2).PlayCount = 0
  Else
    MediaPlayerObject(2).PlayCount = 1
  End If
  MediaPlayerObject(2).Play
End Sub
Sub StopVideo()
  MediaPlayerObject(1).Visible = False
  MediaPlayerObject(1).Stop
  MediaPlayerObject(1).FileName = ""
  Action.UnloadControl MediaPlayerObject(1)
End Sub
Sub StopSound()
  MediaPlayerObject(2).Stop
  MediaPlayerObject(2).FileName = ""
  Action.UnloadControl MediaPlayerObject(2)
End Sub

Then, you can use the "PlayVideo", "StopVideo", "PlaySound" and "StopSound" functions from anywhere in your project.

For example, to play a video in full-screen, type:
PlayVideo "c:\filename.avi", 0, 0, 640, 480, False

To be sure that it works even after the project is compiled (when most file names are scrambled), you should put the files in the "External" subfolder that is inside the project folder, and then use the "GetPath(2)" command to locate the file. Here is the syntax:
PlayVideo GetPath(2) + "filename.avi", 0, 0, 640, 480, False

To make the video loop forever, just replace "False" with "True" in the line above.

To stop the video, simply type:
StopVideo

To play a sound located in the "External" subfolder of your project folder, type:
PlaySound GetPath(2) + "filename.mp3", False

To make the sound loop forever, just replace "False" with "True" in the line above.

To stop the sound, simply type:
StopSound

 

30. How to determine if the player has a specific item in the inventory?

All you have to do is to simply copy/paste the following code into the "VBScript Global Procedures" window (click "VBS Procedures" from the Project Menu of Adventure Maker) (you don't need to modify the code):
 

Function HasItem(ItemName)

 HasItem = False
 For Each X in InventoryItemObject
  If X.Tag = ItemName Then
   HasItem = True
  End If
 Next

End Function

Then, you can use the "HasItem" function from anywhere in your project. This is how to call the function:
HasItem("THE_ITEM_NAME_GOES_HERE")

The function returns "True" if the player has got the item, and "False" otherwise.

For example, to display "True" if the player has got the item named "Key", and to display "False" otherwise, just execute the following code:
MsgBox HasItem("Key")

Note: the item name is the name of the item as it appears in the "Manage Inventory" list of Adventure Maker, not the name of the icon file.

 

31. How to show/hide an item that is already in the inventory?

All you have to do is to simply copy/paste the following code into the "VBScript Global Procedures" window (click "VBS Procedures" from the Project Menu of Adventure Maker) (you don't need to modify the code):
 

Function HideItem(ItemName)
 For Each X in InventoryItemObject
  If X.Tag = ItemName Then
   X.Visible = False
  End If
 Next
End Function

Function ShowItem(ItemName)
 For Each X in InventoryItemObject
  If X.Tag = ItemName Then
   X.Visible = True
  End If
 Next
End Function

Then, you can call the "HideItem(ITEM_NAME)" and "ShowItem(ITEM_NAME)" functions from anywhere in your project.