Blitz3D Lesson4 Error

BlitzMax Forums/BlitzMax Beginners Area/Blitz3D Lesson4 Error

Jillinger(Posted 2014) [#1]
Hi, I seem to have messed up the lesson4.bb file, because Blitz3d demo does not undo changes, unfortunately, and it also apparently auto saves the file, so now the file is messed up.
However, I had created my own file, as I followed the lessons. I am getting this error: Memory Access Violation, and can't get it fixed. Can someone help please.
Here's the code:

; Variables
Global escape_key = 1 ; scancode for ESCape key is 1 - Store it's value in a Global variable we'll name "escape_key"
Global screenW = 640, screenH = 480 ; create a Global variable for the game screen
; Running sound effect handle and volume tags
Global run, run_vol#, runchannel

Graphics3D (screenW,screenH,32,2) ; 32 bit color depth ; windowed
; Running fullscreen can speed up your game significantly in many cases.
SetBuffer BackBuffer() ;

AmbientLight 200, 200, 200 ;add some Ambient light so that if the player gets too far from the point light source things won't go dark
Global myLight_01 = CreateLight(2) ; creates a standard point light. (1 = directional (Default) , 2 = point, 3 = spot)

; create single camera
Global myCam_01 = CreateCamera() ; creates a camera
CameraViewport (myCam_01,0,0,screenW,screenH) ; sets up the view of th camera. This 'sees' the entire game screen.

; Load/Use sprite functions
Include "spriteLoader.bb"
; Load/Use sound functions
Include "soundFunctions.bb" ; INSERTS "soundFunctions.bb" file

;FUNCTIONS
LoadMusic()
LoadSFX()
; Load world randomly with "tree" sprites using our NEW reuseable LoadRandomSprites() function
; Just give the sprite image, how many, and the X and Z range for random placement!
LoadRandomSprites ("tree.bmp", 500, -250, 250, -250, 250) ; call function

; Run a loop as long as no escap key is not pressed - so that I can see what happens
While Not KeyHit(escape_key)

; Use the sprite "RUN" sound volume to toggle sprite animation
If (run_vol# > 0) Then AnimSprite (sprChar, sprCharAnim_tex, 200, 4) ; execute function

UpdateWorld
RenderWorld

Flip
Wend

End


Jillinger(Posted 2014) [#2]
Sorry. Wrong code. Here it is:

;This is my lessons file
; Variables
Global escape_key = 1
Global screenW = 640, screenH = 480 ; create a Global variable for the game screen
Global run, run_vol#, runchannel ; Running sound effect handle and volume tags

Graphics3D (screenW,screenH,32,2) ; 32 bit color depth ; windowed
SetBuffer BackBuffer() ;

AmbientLight 200, 200, 200 ;add some Ambient light so that if the player gets too far from the point light source things won't go dark
Global myLight_01 = CreateLight(2)

; create single camera
Global myCam_01 = CreateCamera()
CameraViewport (myCam_01,0,0,screenW,screenH)

Include "spriteLoader.bb" ; Load/Use sprite functions
Include "soundFunctions.bb" ; INSERTS "soundFunctions.bb" file ; Load/Use sound functions

;FUNCTIONS
LoadMusic()
LoadSFX()
; Load world randomly with "tree" sprites using our NEW reuseable LoadRandomSprites() function
; Just give the sprite image, how many, and the X and Z range for random placement!
LoadRandomSprites ("tree.bmp", 500, -250, 250, -250, 250) ; call function

; Run a loop as long as no escap key is not pressed - so that I can see what happens
While Not KeyHit(escape_key)

; sprite control
; Use the sprite "RUN" sound volume to toggle sprite animation
If (run_vol# > 0) Then AnimSprite (sprChar, sprCharAnim_tex, 200, 4) ; execute function

UpdateWorld
RenderWorld

Flip
Wend

End


;This is the spriteLoader.bb file
; -----------------------------------------------;
; These functions are called from 'lesson003.bb' ;
;------------------------------------------------;

sprChar = CreateSprite()
sprCharAnim_tex = LoadAnimTexture ("char_back.bmp", 7, 32, 48, 0, 4)

EntityTexture (sprChar,sprCharAnim_tex,1) ; the 1 represents either the frame or the index (I'm not sure)
HandleSprite (sprChar,0,-1) ; Sets a sprite handle
ScaleSprite (sprChar,2,2)
PositionEntity (sprChar,0,0,10)

Function LoadRandomSprites (sprite$, total, x1, x2, z1, z2)
temp_sprite = LoadSprite (sprite$,7)
HandleSprite (temp_sprite,0,-1) ; Sets a sprite handle
EntityAutoFade (temp_sprite,100,120)
For s=1 To total ; total 500 trees
sx# = Rnd (x1,x2) : sz# = Rnd (z1,z2) ; randomize
PositionEntity (copied_sprite,sx,0,sz)
ScaleSprite (copied_sprite,Rand(2,3),Rand(4,6))
Next
FreeEntity (temp_sprite)
End Function

Function AnimSprite (obj, atex, d, f)
frame = MilliSecs () /d Mod f
EntityTexture obj,atex,frame
End Function


GfK(Posted 2014) [#3]
You may have more luck posting in the Blitz3D forum.


Jillinger(Posted 2014) [#4]
Thanks. You know I missed that. I'll do that now.