Please help, a VBS noob!

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Please help, a VBS noob!

Postby ffestra » Sat Jun 25, 2011 12:29 pm

Please will someone help me, I'm having a few problems figuring out how to write and where to write certain VB scripts within my game. What I want to do is: once a player has collected a certain number of items in their inventory a sound is played indicating that a hotspot is now enabled.
Many thanks
Ffestra :(
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK

Postby juhuwoorps » Sat Jun 25, 2011 2:37 pm

Hello and welcome to the forums! :)

The first step you have to make is creating a variable for the number of collected item, maybe call it colltected_item_numbers.

in every hotspot you collect an item put this code in the advanced tab:

Code: Select all
colltected_item_numbers=colltected_item_numbers+1
if colltected_item_numbers=number_of_collected_items_need then
play sound
other code...
end if


number_of_collected_items_need is the number of items you want to collect.
To play a sound with vb script, please search the forum for, I dont have it in my memory.
Hope this helps a bit.
If you have further questions, just ask :)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby ffestra » Sat Jun 25, 2011 3:35 pm

Thanks juhuwoorps! :o Very kind of you to help. I tried that and I can't get it to work. Keep getting script errors. So I had a think and tried this:
I created a new 'integer variable' and named it 'itemscar' and I added it to the 'variables the value of which must become 1' of each of the item hotspots that I want in the list of items needed to make the sound play. Am I going in the right direction? I thought then I need to add:
If itemscar=itemscar 1 then Action.PlaySound 'found'
End If

somewhere in the game... any ideas where, and is my scripting correct?
Thank you again juhuwoorps :D
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK

Postby juhuwoorps » Sat Jun 25, 2011 3:57 pm

Don't add it to 'variables the value of which must become 1'

just add this code to every hotspot in the advanced tab:

Code: Select all
itemscar=itemscar+1
if colltected_item_numbers=number_of_collected_items_need then
play sound code

end if


The play sound code depends on what version an what OS you are using.

If you have any errors please post it here. It helps a lot to figure out whats wrong :)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Action.PlaySound error

Postby ffestra » Sat Jun 25, 2011 4:22 pm

Thanks, mate! Sorry to be a complete pain in de butt!
I did what you said, but added the play sound script at the end.

itemscar=itemscar+1
if collected_item_numbers=number_of_collected_items_need then
Action.PlaySound 'found'

end if


When I clicked on the first hotspot item
I got this error message:
Object doen't support this property of method: 'Action.PlaySound'
My bad scripting I guess not sure what to do... :roll:
Cheers, Ffestra :)
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK

Postby juhuwoorps » Sat Jun 25, 2011 4:32 pm

If you want to play sound with vb script you have to add other code to your subroutines.
wich AM version do you use?
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby ffestra » Sat Jun 25, 2011 4:37 pm

Ah, thanks. I have version 4.6.1 (build1) Full Edition
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK

Postby mercedes » Sat Jun 25, 2011 9:14 pm

Hi there, Welcome to the forums..:)

There is a Help link within Adventure Maker... [ The page that comes up can be viewed offline or online]

Playing sound, can be found under the heading; VBS scripts and techniques.

You can copy and paste them..There are all kinds of tips and tricks there..:)
User avatar
mercedes
VIP
 
Posts: 2460
Joined: Sun Mar 09, 2008 10:43 pm
Location: Canada..~

Postby juhuwoorps » Sat Jun 25, 2011 9:21 pm

The code from the helpfile dont work with WIN7. The code for WIN7 and all other Windows Versions is somewhere here on the forum.

You should have a look at the WIN7 section of the forum
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby reneuend » Sun Jun 26, 2011 2:53 am

Hi ffestra,

Welcome to the AM forums!

Here are the procedures you need. Place the following code in the Advanced Tab - Procedures area (click on the Procedures button at the bottom)

NOTE: if you use '0' for NumRepeat it will loop the sound forever until you call the stop procedure.

Code: Select all
Sub PlaySoundWin7(SoundFile, NumRepeat, ChannelNumber)
   If ChannelNumber < 9 Then
      'With VBScript it is currently not possible to interact with the 8 first audio channels.
      MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
      Exit Sub
   End If
   If Action.IsComponentInstalled("NSPlay.NSPlayCtl.1") = False Then
      MsgBox "Unable to find the media player component.", vbCritical, "Error"
   Else
      If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = false Then
         AddComponent "NSPlay.NSPlayCtl.1", "MediaPlayer" + CStr(ChannelNumber)
      End If
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.FileName = SoundFile
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.PlayCount = NumRepeat
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.Play
   End If
End Sub


Sub StopSoundWin7(ChannelNumber)
   If ChannelNumber < 9 Then
      'With VBScript it is currently not possible to interact with the 8 first audio channels.
      MsgBox "The specified audio channel is invalid.", vbCritical, "Error"
      Exit Sub
   End If
   If Action.DoesComponentExist("MediaPlayer" + CStr(ChannelNumber)) = true Then
      Component("MediaPlayer" + CStr(ChannelNumber)).Object.Stop
   End If
End Sub


Now update Juhuwoorps code with the following but REPLACE SoundFile with this: GetPath(4) + "mysoundfile.mp3". and add your sound file to the "Areas" folder found under your project folder where your Adventure Maker program file is located.
Code: Select all
itemscar=itemscar+1
if colltected_item_numbers=number_of_collected_items_need then
   PlaySoundWin7(SoundFile, 1, 10)
end if



Let me know if you have any questions!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby juhuwoorps » Sun Jun 26, 2011 5:27 am

You have to change my code into this:

Code: Select all
itemscar=itemscar+1
if itemscar=5 then
   PlaySoundWin7(SoundFile, 1, 10)
end if



Change the number (5) into the numbers of items you want collect before the sound is played.
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby ffestra » Sun Jun 26, 2011 12:32 pm

Thank you ever so much guys :D I'll let you know how I get on!
Thanks again!
Ffestra x
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK

Postby juhuwoorps » Sun Jun 26, 2011 12:40 pm

No matter :)

I have a peak on your blog. If you're going to use your drawing skills for a game this just can be a good game.

Really nice pictures and ideas.
It would be nice to have a 5 friends game made with AM :)
juhuwoorps
Code Master
 
Posts: 622
Joined: Tue Jul 08, 2008 3:13 pm

Postby ffestra » Sun Jun 26, 2011 7:25 pm

Thanks juhu! You're very kind :D
User avatar
ffestra
Junior Member
 
Posts: 9
Joined: Thu Jan 07, 2010 10:40 pm
Location: Snowdonia, UK


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron