program crash with sound

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.

Hi!

when i click on this position then my programm crash

Code: Select all

If MouseX() > 320 And MouseX()  220 And MouseY() < 300 
   PFRAME = 6 
   SFRAME = 12
   If MouseButton(1)
   PlaySound(1,0)
   STARTB = 1
   EndIf 
   Else 
   SFRAME = 4 
 EndIf 
cya
bluespeed

http://www.purehilfe.de.vu
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi blue-speed!
Are you using a screen or window for your program you are working on? Have you init all needed stuff like "InitMouse(), IntitSound(#num), InitScreen(), InitSprite() i.e. at the programstart?

Mhhhh... if you want to check keys or mouse changes, you have to use reset/update this everytime by using ExamineMouse() or ExamineKeyboard() before you test the key or mouse for example.

Send the full source or give us some more infos, what you are using (screen, window) and what you want to code, so we could help you a bit more...

Code: Select all

    ExamineMouse()
    ;
    If MouseX() > 320 And MouseX()  220 And MouseY() < 300 
        PFRAME = 6   
        SFRAME = 12
        ExamineMouse()
        ;
        If MouseButton(1)
          PlaySound(1,0)
          STARTB = 1
        EndIf
        ; 
      Else 
        ;
        SFRAME = 4 
    EndIf 

Have you tested if all went ok - when Init(), Open(), Load() stuff... this is the first think i would check... As the topic say, the program crash only when using Sound()? If so, please check if you have InitSound() at programstart, loading the right sample (wave format) correctly...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.
Hi blue-speed!
Are you using a screen or window for your program you are working on? Have you init all needed stuff like "InitMouse(), IntitSound(#num), InitScreen(), InitSprite() i.e. at the programstart?
its for a game-menue, i use a fullscreen. Ive init all the stuff that i need, but initscreen()??
Mhhhh... if you want to check keys or mouse changes, you have to use reset/update this everytime by using ExamineMouse() or ExamineKeyboard() before you test the key or mouse for example.
ive write the code in a procedure which i call in the main loop like this:
repeat
examinekeyboard()
examinemouse()
MenueGameProcedure()
...
Send the full source or give us some more infos, what you are using (screen, window) and what you want to code, so we could help you a bit more...

Code: Select all

    ExamineMouse()
    ;
    If MouseX() > 320 And MouseX()  220 And MouseY()  320 And MouseX()  220 And MouseY()  90 And MouseX()  350 And MouseY()  550 And MouseX()  350 And MouseY() < 500 
   PFRAME = 7 
   QFRAME = 13
   If MouseButton(1)
   QUITB = 1
   EndIf
   Else 
   QFRAME = 5 
 EndIf
EndProcedure
 ;------------------------------

;--------------------------------------------------------------------
; H A U P T S C H L E I F E 
;--------------------------------------------------------------------
 PlayMovie(10,0)
 Repeat  
     FlipBuffers()
     ClearScreen(0,0,0)
     ExamineKeyboard()
     ExamineMouse()
      
          If OK = 0
          Gosub Draw_Intro
          EndIf
       
          If OK = 1
          Move_Pfeil()
          Gosub Draw_Menue
          EndIf 
          
          If STARTB = 1
          Gosub Game_Start
          EndIf
          
          If CREDITB = 1
          Gosub Game_Credits
          EndIf
          
          If QUITB = 1
          Gosub Game_Quit
          EndIf
        
 Until KeyboardPushed(#PB_Key_Escape)
 EndIf
http://www.purehilfe.de.vu
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.

i miss the gamecoder .

http://www.purehilfe.de.vu
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
blue-speed wrote:
miss the gamecoder .
Hi blue-speed
I am coding on a game and maybe you can call me as PB gamecoder, hehe... i havent had the time to check your example yet but i will check it asap... (full game source + datas would be easy to see/find your problem.... but i will have a look to your example next 2 days when having some more time... Or just write me an email (german) and we could get in contact via voice i.e ...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi blue-speed!
I know the problem if you have a problem with your code and waiting for an answer which could help you to solve the problem - So i spent all my time in checking your code snip and wrote a small working example... I hope it is what you wanted... :wink: Have a look to it and report me if its ok :wink:

Code: Select all


;---------------------------------------------
; StartUp -> Init all the needed system stuff
;---------------------------------------------
;
    If InitMovie() = 0 
      MessageRequester("Error", "Can't initialize movie playback!", 0) 
      End        ; If Init() failed, we will quit our program!
    EndIf    
;
    If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
      MessageRequester("Error", "Can't open DirectX 7 Or later",0)
      End        ; If Init() failed, we will quit our program!
    EndIf
;
    If InitSound(10) = 0
      MessageRequester("Error", "Can't open DirectX 7 Or SoundCard is not present",0)
      End        ; If Init() failed, we will quit our program!
    EndIf
;
    If OpenScreen(800,600,32,"Break-It") = 0
      MessageRequester("Error","Could not open 800x600x32 screen",0)
      End        ; If OpenScreen failed, we will quit our program!
    EndIf
;
;----------------------------    
; StartUp -> Init global var 
;----------------------------
;
    Global OK      :   OK         = 0 
    Global PLAYED  :   PLAYED     = 0
    Global PFRAME  :   PFRAME     = 6
    Global QFRAME  :   QFRAME     = 5
    Global CFRAME  :   CFRAME     = 3  
    Global SFRAME  :   SFRAME     = 4
    Global STARTB  :   STARTB     = 0  
    Global CREDITB :   CREDITB    = 0
    Global QUITB   :   QUITB      = 0
    ;
    Global BOX1,BOX2,BOX3
;
;----------------------------
; StartUp -> Load SoundDatas 
;----------------------------
;
    LoadSound (0 ,"sfx\boing.wav")
    LoadSound (1 ,"sfx\bonk.wav")
    LoadSound (2 ,"sfx\evil-laf.wav")
;
;----------------------------
; StartUp -> Load MusicDatas
;----------------------------
;
    LoadMovie (0 ,"sfx\level1.mid")
    LoadMovie (1 ,"sfx\level2.mid")
;
;----------------------------
; StartUp -> Our Procedures
;----------------------------
;
    Procedure Move_Pfeil()                
      ;
      ;-------- Check Button 1 (red) --------
      ;                        
      If MouseX() > 320 And MouseX()  220 And MouseY()  90 And MouseX()  350 And MouseY()  550 And MouseX()  350 And MouseY()  DrawIntro
;----------------------------------------
Draw_Intro:
;    
    mygosub$ = "Gosub Draw_Intro"
Return
;
;----------------------------------------
; Subroutine -> DrawMenu
;----------------------------------------
Draw_Menue:
;
     mygosub$ = "Gosub Draw_Menue"
Return
;
;----------------------------------------
; Subroutine -> GameStart
;----------------------------------------
Game_Start:
;
     mygosub$ = "Gosub Game_Start"
Return
;
;----------------------------------------
; Subroutine -> GameCredits 
;----------------------------------------
Game_Credits:
;
     mygosub$ = "Gosub Game_Credits"
Return
;
;----------------------------------------
; Subroutine -> Game_Quit
;----------------------------------------
Game_Quit:
;
     mygosub$ = "Gosub Game_Quit"
Return
;
;----------------------------------------
; Subroutine -> Draw boxes for example
;----------------------------------------
SUB_MrVainExample:
;
    StartDrawing(ScreenOutput())
        FrontColour (255,0,0)  ; Box1 (red)
        Box(320,220,200,80)
        ;
        FrontColour (0,255,0)  ; Box2 (green)
        Box(90,350,100,150)
        ;
        FrontColour (0,0,255)  ; Box3 (blue)
        Box(550,350,100,150)
    StopDrawing()
    ;
Return
;
;----------------------------------------
; Subroutine -> Draw boxes for example
;----------------------------------------
SUB_CreateMousePointer:
;  
    StartDrawing(ScreenOutput())
        FrontColour (127,127,127)
        Box (0,0,16,16)
    StopDrawing()
    ;
    GrabSprite (0,0,0,16,16)
    ;
Return
;
;----------------------------------------
; Subroutine -> Debugger - Print Vars()
;----------------------------------------
SUB_PrintResults:
;
    StartDrawing(ScreenOutput())
       FrontColour(255,255,255)
       DrawingMode(1)
       Locate (20, 40) : DrawText("MouseX: "+Str(MouseX()))
       Locate (20, 55) : DrawText("MouseY: "+Str(MouseY()))
       ;      
       Locate (20,100) : DrawText("OK: "+Str(OK))
       Locate (20,115) : DrawText("PLAYED: "+Str(PLAYED))
       Locate (20,130) : DrawText("PFRAME: "+Str(PFRAME))
       Locate (20,145) : DrawText("QFRAME: "+Str(QFRAME))
       Locate (20,160) : DrawText("CFRAME: "+Str(CFRAME))
       Locate (20,175) : DrawText("SFRAME: "+Str(SFRAME))
       Locate (20,190) : DrawText("STARTB: "+Str(STARTB))
       Locate (20,205) : DrawText("CREDITB: "+Str(CREDITB))
       Locate (20,220) : DrawText("QUITB: "+Str(QUITB))
       ; 
       Locate (320,380) : DrawText("Box1: "+Str(BOX1))
       Locate (320,395) : DrawText("Box2: "+Str(BOX2))
       Locate (320,410) : DrawText("Box3: "+Str(BOX3))
       ;
       Locate (320,100) : DrawText("ProgramStatus: "+mygosub$) 
   StopDrawing()
Return
;
;---------------------------------------- 
This example works very fine ony my machine, playing background midi tune and when klicking on the red box you will listen to the *.wav sample Good luck...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.

Hi!

Thx for the help . I hope u dont understand it wrong, but i dont want to paste this code cz all things are modified (for example the comments). What i want is the error in my code. I think there isnt any problem with examinekeyboard or examinemouse and there isn any problems with the init stuff.
So where is the error? Its only a question not a atack .



cya bluespeed
PS:
PlayMovie(1,ScreenID()) ; ### Here you wrote to play tune number 10 (does it exist?) ###
yes it does exist, ive cut some code snips out.

http://www.purehilfe.de.vu

Edited by - blue-speed on 19 February 2002 12:44:10
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> i dont want to paste this code cz all things are modified

So backup your current code before pasting this test code.


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
PB wrote:
So backup your current code before pasting this test code.
Yes - i think its normal to have every time a backup and espectly when trying a new code part

Hi blue-speed
Sorry, i dont modified a lot... and in your code there where no comments... I just wrote all in english, so everybody can understand the code and not only germans :wink: Btw. verify your code with my to find your bug... I wrote just only a working example that everybody can see the result... You have just to cut all the labels (subroutines) in my source and you have to remove "Global BOX1,BOX2,BOX3" and there VARs - else its excatly your old code snip i only formated a bit to get it more readable... Good luck...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi blue-speed
Thanks for sending me you source with all your datafiles... Finaly i found the reason for you problem... its not a bug of PB nor a bug in you source... Your *wav samples are all corrupt... You can play it with WinAmp for example, yes... But the structure arent really ok of your samples, so you have to convert they all again, using a tracker or any other sound reladed tool... Btw i have fixed/converted all you samples and send you via email... Now it works very fine...

Btw i think you should change the code of your Draw_Intro: subroutine...
Your code looks like:

Code: Select all

    If KeyboardPushed(#PB_Key_Space)
      Delay(2000)
      OK = 1
    EndIf
I would preffer to write as like following:

Code: Select all

    Delay(2000)
    If KeyboardPushed(#PB_Key_Space)
      OK = 1
    EndIf
Because when pressing the SPACE key the user will see any changes and dont want to wait again some seconds... So just set the delay() before waiting for any keyinput :wink: bye


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.
Hi blue-speed
Thanks for sending me you source with all your datafiles... Finaly i found the reason for you problem... its not a bug of PB nor a bug in you source... Your *wav samples are all corrupt... You can play it with WinAmp for example, yes... But the structure arent really ok of your samples, so you have to convert they all again, using a tracker or any other sound reladed tool... Btw i have fixed/converted all you samples and send you via email... Now it works very fine...
thanks now when i play the "fixed" sounds then i dont hear the sound i hear a zischen but thanks for ur help .

Code: Select all

    If KeyboardPushed(#PB_Key_Space)
      Delay(2000)
      OK = 1
    EndIf
the user have to wait 2000ms so he cant press immediatly space to get faster in the menu he must wait 2000ms.

Code: Select all

    Delay(2000)
    If KeyboardPushed(#PB_Key_Space)
      OK = 1
    EndIf
Because when pressing the SPACE key the user will see any changes and dont want to wait again some seconds... So just set the delay() before waiting for any keyinput :wink: bye
hm... where is the idea in this code?
Its the same like the code on the top. like urs or like mine the have to wait damn it *g*, when i put it like ur code then ive to press 10-15 times on the space button to get in the menu dont know why... and when i put it in a if tag then i can feel sure that it works ONLY when the if tag is true, in my code does it mean when i pressed the space button. So in your example it works with press 15 times on the space button and i cant find the problem. I call that "Wilder delay command" *g* cz u arent sure what else can delayed when u put like i call it "in freier code-zone" *g*.


http://www.purehilfe.de.vu

Edited by - blue-speed on 20 February 2002 00:25:30
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi blue-speed
Sorry... i think i send you the wrong converted sample archive... ups... Just use any soundtool or tracker, load your old samples into the tool and save it again as microsoft *wave... This should solve your problem...

The two codesnips i posted you - are different!! When you start your game. the user have to wait (delay 2000) and will see the titlepicture... then the user can press the spacebar and in the moment the user will see the menu screen... Also just write Delay() before you check any key input... Or do you like to have a game, press spacebar and you dont know that the program have registred this and will go in a few seconds to the menuscreen? :wink:) Hope you know what i want to say...!? Bye


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blue-speed.

Hi
When you start your game. the user have to wait (delay 2000) and will see the titlepicture... then the user can press the spacebar and in the moment the user will see the menu screen...
when u have my code try to write u code example in it and ull c some problems like press 15 times on space button to get in the menue. I know what u mean, u dont want to press the space button to wait 2000ms to get in, u want to get in immidiatly but i dont want it

http://www.purehilfe.de.vu
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
blue-speed wrote:
when u have my code try to write u code example in it and ull c some problems like press 15 times on space button to get in the menue.
Mhhhh... i dont see there any problems... sorry, but at the moment i have some privat problems and not so much time to write you a working example... When i have some more time, i will ofcourse send you a working (modified) example... I think to have some more time after eastern... please be patienced and keep on your work
I know what u mean, u dont want to press the space button to wait 2000ms to get in, u want to get in immidiatly but i dont want it
Yes, exact - you understand me :wink: Btw. why do you not want it? Greetz..


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
Post Reply