help, it's not working! crashing code random
Posted: Mon Mar 02, 2020 5:29 am
Hello, please tell me why this code is crashing?
Declare speak(text$)
Declare sound(name$,anchor,other)
Structure sound
name.s
id.i
EndStructure
Global NewList sounds.sound()
Global espawntimer=25000
Global ispawntimer = 40000
Global weapontimer = 0
Global fcd = 20
Structure enemy
health.l
x.l
EndStructure
Global NewList enemies.enemy()
Global enemytimer = 180
Global itemtimer=900
Structure item
x.l
EndStructure
Global NewList items.item()
Procedure enemy()
AddElement(enemies())
enemies()\x = 20
enemies()\health = 50
EndProcedure
Procedure moreitems()
For i = 1 To 3
AddElement(items())
items()\x=Random(40,1)
Next
EndProcedure
Global walktimer = 180
Global pushvar1=0
Global wdamage = 0
Global wrange = 0
Global wtime = 0
Global weapon.s = ""
Global x = 0
Global health = 100
#left$ = Chr(37)
#up$ = Chr(38)
#right$ = Chr(39)
#down$ = Chr(40)
InitKeyboard()
XIncludeFile "tolk.pb"
tolk::load()
tolk::detectscreenreader()
Global x = 0
InitSprite()
InitSound()
UseOGGSoundDecoder()
Procedure gd(anchor,other)
ProcedureReturn other-anchor
EndProcedure
Procedure sound(name$,anchor,other)
did = 0
If did = 0
bla = Random(2000,1)
AddElement(sounds())
sounds()\id = bla
sounds()\name = name$
LoadSound(bla,name$)
SoundVolume(bla,100-Abs(gd(anchor,other))*6)
SoundPan(bla,gd(anchor,other)*6)
PlaySound(bla)
EndIf
EndProcedure
Procedure speak(text$)
tolk::output(text$)
EndProcedure
moreitems()
enemy()
OpenScreen(800,600,32,"test")
mehple = LoadSound(2001,"gamemus.ogg")
PlaySound(2001,#PB_Sound_Loop)
meh = LoadSound(0,"bar1.ogg")
PlaySound(0)
Procedure itemcheckloop()
ForEach items()
sound("ite2.ogg",x,items()\x)
If x = items()\x
speak("health boost!")
health + 10
DeleteElement(items())
Continue
EndIf
Next
EndProcedure
Repeat
FlipBuffers()
ExamineKeyboard()
press$ = KeyboardInkey()
If KeyboardPushed(#PB_Key_LeftAlt) And KeyboardReleased(#PB_Key_Y)
speak(Str(MemoryStatus(#PB_System_FreePhysical)/1000000))
EndIf
If KeyboardPushed(#PB_Key_2) And weapon<> "machinegun"
speak("machinegun.")
sound("machinegundraw.ogg",x,x)
weapon = "machinegun"
weapontime = 90
weapondamage = 5
weaponrange = 10
EndIf
If KeyboardPushed(#PB_Key_3) And weapon <> "eagle"
sound("desert_eagledraw.ogg",x,x)
speak("desert eagle.")
weapon = "eagle"
weaponrange = 8
weapondamage = 8
weapontime = 160
EndIf
If ElapsedMilliseconds() > weapontimer
If KeyboardPushed(#PB_Key_Space) And weapon<> ""
sound(weapon+".ogg",0,0)
weapontimer = ElapsedMilliseconds() + weapontime
ForEach enemies()
If enemies()\x<x+weaponrange And enemies()\x>x-weaponrange
sound("guy1hit"+Random(3,1)+".ogg",x,enemies()\x)
sound("body"+Random(3,1)+".ogg",x,enemies()\x)
enemies()\health - weapondamage
EndIf
If enemies()\health < 1
sound("guy"+Random(5,1)+"death.ogg",x,enemies()\x)
DeleteElement(enemies())
Continue
EndIf
Next
EndIf
EndIf
If press$ = "c"
speak(Str(x))
EndIf
If ElapsedMilliseconds() > walktimer
If KeyboardPushed(#PB_Key_A) And x > 0
itemcheckloop()
walktimer = ElapsedMilliseconds() + 180
Debug1 = ElapsedMilliseconds()
sound("cementstep"+Random(5,1)+".ogg",0,0)
x - 1
debug2 = ElapsedMilliseconds()
debug2 - Debug1
EndIf
EndIf
If ElapsedMilliseconds() > walktimer
If KeyboardPushed(#PB_Key_D) And x < 40
walktimer = ElapsedMilliseconds() + 180
itemcheckloop()
x + 1
sound("cementstep"+Random(5,1)+".ogg",0,0)
EndIf
EndIf
If press$ = "h"
speak(""+health+" health.")
EndIf
If KeyboardPushed(#PB_Key_1) And pushvar1 = 0
pushvar1 = 1
weapon = "sniper_rifle"
speak(weapon)
sound("sniper_rifledraw.ogg",0,0)
weapontime=2000
weapondamage=20
weaponrange=20
EndIf
If KeyboardReleased(#PB_Key_1)
pushvar1 = 0
EndIf
If ElapsedMilliseconds() > itemtimer
itemtimer = ElapsedMilliseconds() + 600
EndIf
If health < 1
sound("death.ogg",x,x)
Delay(1000)
End
EndIf
If ElapsedMilliseconds() > enemytimer
fcd - 1
enemytimer = ElapsedMilliseconds() + 180
ForEach enemies()
If enemies()\x < x
enemies()\x + 1
sound("cementstep"+Random(5,1)+".ogg",x,enemies()\x)
EndIf
If enemies()\x > x
enemies()\x - 1
sound("cementstep"+Random(5,1)+".ogg",x,enemies()\x)
EndIf
If enemies()\x = x And fcd < 1
sound("knifehit.ogg",0,0)
health - 10
fcd = 3
EndIf
Next
EndIf
If ElapsedMilliseconds() >espawntimer
espawntimer = ElapsedMilliseconds() + 15000
enemy()
EndIf
If ElapsedMilliseconds() > ispawntimer
ispawntimer = ElapsedMilliseconds() + 30000
moreitems()
EndIf
ForEach sounds()
If SoundStatus(sounds()\id) = #PB_Sound_Stopped
FreeSound(sounds()\id)
DeleteElement(sounds())
Break
EndIf
Next
Until nevergonnahappen = 1
Also, if there are any stupid variables names, it's because it was started when i just finished raging at videogames, or just because I was in a rush.
Also, if the code is mess up, can you help to clean it a bit?
Thanks in advance.
I know it's not clean at all I know.
just these crashes are confusing me a lot. also this is my first attempt at a pure basic game. let me describe the crashing: it just glitches out, pulls an error and then stops playing anything.
Declare speak(text$)
Declare sound(name$,anchor,other)
Structure sound
name.s
id.i
EndStructure
Global NewList sounds.sound()
Global espawntimer=25000
Global ispawntimer = 40000
Global weapontimer = 0
Global fcd = 20
Structure enemy
health.l
x.l
EndStructure
Global NewList enemies.enemy()
Global enemytimer = 180
Global itemtimer=900
Structure item
x.l
EndStructure
Global NewList items.item()
Procedure enemy()
AddElement(enemies())
enemies()\x = 20
enemies()\health = 50
EndProcedure
Procedure moreitems()
For i = 1 To 3
AddElement(items())
items()\x=Random(40,1)
Next
EndProcedure
Global walktimer = 180
Global pushvar1=0
Global wdamage = 0
Global wrange = 0
Global wtime = 0
Global weapon.s = ""
Global x = 0
Global health = 100
#left$ = Chr(37)
#up$ = Chr(38)
#right$ = Chr(39)
#down$ = Chr(40)
InitKeyboard()
XIncludeFile "tolk.pb"
tolk::load()
tolk::detectscreenreader()
Global x = 0
InitSprite()
InitSound()
UseOGGSoundDecoder()
Procedure gd(anchor,other)
ProcedureReturn other-anchor
EndProcedure
Procedure sound(name$,anchor,other)
did = 0
If did = 0
bla = Random(2000,1)
AddElement(sounds())
sounds()\id = bla
sounds()\name = name$
LoadSound(bla,name$)
SoundVolume(bla,100-Abs(gd(anchor,other))*6)
SoundPan(bla,gd(anchor,other)*6)
PlaySound(bla)
EndIf
EndProcedure
Procedure speak(text$)
tolk::output(text$)
EndProcedure
moreitems()
enemy()
OpenScreen(800,600,32,"test")
mehple = LoadSound(2001,"gamemus.ogg")
PlaySound(2001,#PB_Sound_Loop)
meh = LoadSound(0,"bar1.ogg")
PlaySound(0)
Procedure itemcheckloop()
ForEach items()
sound("ite2.ogg",x,items()\x)
If x = items()\x
speak("health boost!")
health + 10
DeleteElement(items())
Continue
EndIf
Next
EndProcedure
Repeat
FlipBuffers()
ExamineKeyboard()
press$ = KeyboardInkey()
If KeyboardPushed(#PB_Key_LeftAlt) And KeyboardReleased(#PB_Key_Y)
speak(Str(MemoryStatus(#PB_System_FreePhysical)/1000000))
EndIf
If KeyboardPushed(#PB_Key_2) And weapon<> "machinegun"
speak("machinegun.")
sound("machinegundraw.ogg",x,x)
weapon = "machinegun"
weapontime = 90
weapondamage = 5
weaponrange = 10
EndIf
If KeyboardPushed(#PB_Key_3) And weapon <> "eagle"
sound("desert_eagledraw.ogg",x,x)
speak("desert eagle.")
weapon = "eagle"
weaponrange = 8
weapondamage = 8
weapontime = 160
EndIf
If ElapsedMilliseconds() > weapontimer
If KeyboardPushed(#PB_Key_Space) And weapon<> ""
sound(weapon+".ogg",0,0)
weapontimer = ElapsedMilliseconds() + weapontime
ForEach enemies()
If enemies()\x<x+weaponrange And enemies()\x>x-weaponrange
sound("guy1hit"+Random(3,1)+".ogg",x,enemies()\x)
sound("body"+Random(3,1)+".ogg",x,enemies()\x)
enemies()\health - weapondamage
EndIf
If enemies()\health < 1
sound("guy"+Random(5,1)+"death.ogg",x,enemies()\x)
DeleteElement(enemies())
Continue
EndIf
Next
EndIf
EndIf
If press$ = "c"
speak(Str(x))
EndIf
If ElapsedMilliseconds() > walktimer
If KeyboardPushed(#PB_Key_A) And x > 0
itemcheckloop()
walktimer = ElapsedMilliseconds() + 180
Debug1 = ElapsedMilliseconds()
sound("cementstep"+Random(5,1)+".ogg",0,0)
x - 1
debug2 = ElapsedMilliseconds()
debug2 - Debug1
EndIf
EndIf
If ElapsedMilliseconds() > walktimer
If KeyboardPushed(#PB_Key_D) And x < 40
walktimer = ElapsedMilliseconds() + 180
itemcheckloop()
x + 1
sound("cementstep"+Random(5,1)+".ogg",0,0)
EndIf
EndIf
If press$ = "h"
speak(""+health+" health.")
EndIf
If KeyboardPushed(#PB_Key_1) And pushvar1 = 0
pushvar1 = 1
weapon = "sniper_rifle"
speak(weapon)
sound("sniper_rifledraw.ogg",0,0)
weapontime=2000
weapondamage=20
weaponrange=20
EndIf
If KeyboardReleased(#PB_Key_1)
pushvar1 = 0
EndIf
If ElapsedMilliseconds() > itemtimer
itemtimer = ElapsedMilliseconds() + 600
EndIf
If health < 1
sound("death.ogg",x,x)
Delay(1000)
End
EndIf
If ElapsedMilliseconds() > enemytimer
fcd - 1
enemytimer = ElapsedMilliseconds() + 180
ForEach enemies()
If enemies()\x < x
enemies()\x + 1
sound("cementstep"+Random(5,1)+".ogg",x,enemies()\x)
EndIf
If enemies()\x > x
enemies()\x - 1
sound("cementstep"+Random(5,1)+".ogg",x,enemies()\x)
EndIf
If enemies()\x = x And fcd < 1
sound("knifehit.ogg",0,0)
health - 10
fcd = 3
EndIf
Next
EndIf
If ElapsedMilliseconds() >espawntimer
espawntimer = ElapsedMilliseconds() + 15000
enemy()
EndIf
If ElapsedMilliseconds() > ispawntimer
ispawntimer = ElapsedMilliseconds() + 30000
moreitems()
EndIf
ForEach sounds()
If SoundStatus(sounds()\id) = #PB_Sound_Stopped
FreeSound(sounds()\id)
DeleteElement(sounds())
Break
EndIf
Next
Until nevergonnahappen = 1
Also, if there are any stupid variables names, it's because it was started when i just finished raging at videogames, or just because I was in a rush.
Also, if the code is mess up, can you help to clean it a bit?
Thanks in advance.
I know it's not clean at all I know.
just these crashes are confusing me a lot. also this is my first attempt at a pure basic game. let me describe the crashing: it just glitches out, pulls an error and then stops playing anything.