Skip to main content
gamedev.net
🔒 Locked

BlitzBasic Question

Started by SuperBokey 4 replies 1k views
Original Post
SuperBokey
SuperBokey
I have a little problem here.. Whenever I compile my code, it will for a few seconds (after moving the character around a bit) and then it gives me an error about illegal memory address. I've searched my code and I could find whats wrong. In my walking bitmaps I have 7 images of the guy walking (just incase you need that info) Here's my code: Graphics 800,600,16,3 AutoMidHandle True SetBuffer BackBuffer() ;GLOBALS/TYPES Global fps = CreateTimer(12) Global frames = 0 Type Hero Field x,y,frame,action;action: 1-Stand,2-Walk,3-Run Field img,dir;dir: 1-Right,2-Left Field imgwl,imgwr Field imgsl,imgsr End Type ;INITS Global Baleog.Hero = New Hero Baleog\x = 400 Baleog\y = 300 Baleog\frame = 0 Baleog\action = 1 Baleog\dir = 1 Baleog\imgwl = LoadAnimImage("Baleog\BaleogWalkLeft.bmp",33,32,0,7) Baleog\imgwr = LoadAnimImage("Baleog\BaleogWalkRight.bmp",33,32,0,7) Baleog\imgsl = LoadImage("Baleog\BaleogStandLeft.bmp") Baleog\imgsr = LoadImage("Baleog\BaleogStandRight.bmp") Baleog\img = Baleog\imgsr MaskImage Baleog\imgwl,255,0,255 MaskImage Baleog\imgwr,255,0,255 MaskImage Baleog\imgsl,255,0,255 MaskImage Baleog\imgsr,255,0,255 ;MAIN LOOP While(Not KeyDown(1)) frames = WaitTimer(fps) For i=0 To frames UpdateGame() Next Cls RenderHero() Flip Wend End ;FUNCTIONS Function UpdateGame() If(KeyDown(205)) Baleog\x = Baleog\x+5 Baleog\frame = Baleog\frame+1 Baleog\dir = 1 Baleog\action = 2 ElseIf(KeyDown(203)) Baleog\x = Baleog\x-5 Baleog\frame = Baleog\frame-1 Baleog\dir = 0 Baleog\action = 2 Else Baleog\action = 1 EndIf If(Baleog\frame < 0) Baleog\frame = 6 ElseIf(Baleog\frame > 6) Baleog\frame = 0 EndIf End Function Function RenderHero() Select Baleog\action Case 1;Stand If Baleog\dir=1;Right Baleog\img = Baleog\imgsr Else;Left Baleog\img = Baleog\imgsl EndIf Case 2;Walk If Baleog\dir=1 Baleog\img = Baleog\imgwr Else Baleog\img = Baleog\imgwl EndIf End Select DrawImage Baleog\img,Baleog\x,Baleog\y,Baleog\frame End Function
Kekko
Kekko
;FUNCTIONS
Function UpdateGame()
If(KeyDown(205))
Baleog\x = Baleog\x+5
Baleog\frame = Baleog\frame+1
Baleog\dir = 1
Baleog\action = 2
ElseIf(KeyDown(203))
Baleog\x = Baleog\x-5
Baleog\frame = Baleog\frame-1
Baleog\dir = 0
Baleog\action = 2
Else
Baleog\action = 1
Baleog\frame = 0 <<<=== This is the fix.
EndIf


If your hero stops, you have to set the frame to 0. Otherwise it will attempt to draw a nonexisting frame from the standing image. Which is an illegal memory adress.
spacemonkey90
spacemonkey90
Make sure the size of your frame is accurate. If you set it too big then there's not enough image their to create the 7 frames your requesting. I've had the problem in the past and I've found that by just clipping a pixel or two from the size fixes the problem. Be careful not to set the frame size too small though or some will end up getting cut in half.
SuperBokey
SuperBokey
I figured out the frame thing, but how would I be able to pass a type as an arguement for one of my functions? For example:

type Obj
field x,y,img
end type

enemy1.Obj = new Obj

function createEnemy(name,x,y)
name\x = x
name\y = y
name\img = loadimage("enemy.bmp")
end function

createEnemy(enemy1,200,30)

Or something like that.. BlitzBasic isnt letting me pass a type for the parameter..
Kekko
Kekko
function createEnemy(name.Obj, x, y)


Like so, if I remember correctly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.