memory erase

Blitz3D Forums/Blitz3D Beginners Area/memory erase

Ben(t)(Posted 2008) [#1]
is there a way to erase all loaded data from blitz3d? I have a level where I want the player to respawn at the origional location but when I respawn, nothing is there except for the level


Ben(t)(Posted 2008) [#2]
never mind I need help on this

Graphics3D 640,480,16,2
SeedRnd MilliSecs()
AmbientLight 50,50,50

Global screenbk=CreateImage(GraphicsWidth(),GraphicsHeight())
Global underw_a

gamespeed#=1

players=1
shots=2
items=3
walls=4
water=5

light=CreateLight()
TurnEntity light,90,0,0

Dim floatdie(3)
Dim ow(8)
Dim die(4)
Dim drown(2)
Dim ricochet(3)



reticle=LoadAnimImage("gfx\pointer.bmp",27,27,0,15)

ammo=LoadMesh("3ds\items\ammo-50.b3d")
EntityShininess ammo,5
EntityType ammo,items
HideEntity ammo

turret=LoadAnimMesh("3ds\bots\turret.b3d")
ExtractAnimSeq(turret,1,15)
ExtractAnimSeq(turret,15,30)
ExtractAnimSeq(turret,30,45)
EntityShininess turret,1
EntityType turret,players
HideEntity turret

floater=LoadAnimMesh("3ds\bots\floater.b3d")
EntityShininess floater,1
EntityType floater,players
HideEntity floater

Gosub setup
Gosub playsetup

.gameload

fire=MilliSecs()
mx#=0
mz#=0
my#=0
falldamage=0
fallbase#=0
fallheight#=0
waterdamage=0
height#=6
jump=False
zoom#=0
controlvolume#=1
Ammo=100
clipammo=200
Replacement=0
falldeath#=-500
liquid#=-3
health#=100
armor#=100

levelload$="lvls\station1"


c=LoadMesh(levelload$+".b3d")
EntityColor c,255,255,255
ScaleEntity c,2,2,2
MoveEntity c,0,-5,0
EntityType c,walls
EntityPickMode c,2

info=ReadFile(levelload$+".dat")

If info<>0 Then
While unit$<>"end"
unit$=ReadString$(info)
x#=ReadFloat(info)
y#=ReadFloat(info)
z#=ReadFloat(info)
rx#=ReadFloat(info)
ry#=ReadFloat(info)

If unit$="player" Then
HideEntity feet
HideEntity eyes

PositionEntity feet,x#,y#+5,z#
RotateEntity feet,0,ry#,0
RotateEntity eyes,rx#,0,0
ShowEntity feet
ShowEntity eyes

EndIf

If unit$="bot" Then
f.floater=New floater
f\entity=CopyEntity(floater)
HideEntity f\entity
EntityPickMode f\entity,2
f\fire=-5
f\alpha#=1
f\healthmax#=1
f\health#=1
f\target=0
PositionEntity f\entity,x#,y#,z#
RotateEntity f\entity,rx#,ry#,0
ShowEntity f\entity
EndIf

If unit$="ammo" Then
a.ammo=New ammo
a\entity=CopyEntity(ammo)
HideEntity a\entity
a\alpha#=1
PositionEntity a\entity,x#,y#+2,z#
RotateEntity a\entity,rx#,ry#,0
EntityType a\entity,items
ShowEntity a\entity
EndIf

If unit$="turret" Then
t.turret=New turret
t\entity=CopyEntity(turret)
HideEntity t\entity
EntityPickMode t\entity,2
t\fire=-5
t\alpha#=1
t\health#=1
t\target=0
PositionEntity t\entity,x#,y#,z#
RotateEntity t\entity,rx#,ry#,0
ShowEntity t\entity
EndIf

Wend
EndIf
CloseFile(info)


liquids=LoadAnimTexture("gfx\anim water.bmp",1,128,128,0,15)
ScaleTexture liquids,15,15

plane=CreatePlane()
PositionEntity plane,0,liquid#,0
EntityAlpha plane,.5
EntityType plane,water
stars=LoadTexture("gfx\stars.bmp")
ScaleTexture stars,.1,.1

sky=loadskybox("gfx\sky")
EntityParent sky,eyes
EntityOrder sky,4
EntityPickMode sky,2

tech=LoadFont("blitz",16,1,0,0)
death=LoadFont("chiller",128,0,0,0)

Collisions players,walls,2,3
Collisions players,items,2,3
Collisions players,players,2,1
Collisions shots,walls,2,1
Collisions shots,players,2,1
Collisions shots,items,2,1
Collisions shots,water,2,1
Collisions items,walls,2,3
Collisions items,players,2,3
Collisions items,items,2,3

HidePointer
MoveMouse GraphicsWidth()/2,GraphicsHeight()/2

SetFont tech

While Not KeyHit(1)
PositionTexture liquids,15,45
frame=MilliSecs()/50 Mod 15
EntityTexture plane,liquids,frame

RotateEntity sky,0,0,0,1

If KeyDown(15) Then
gamespeed#=gamespeed#+1
Else gamespeed#=gamespeed#-1
EndIf

If gamespeed#<1 Then gamespeed#=1
If gamespeed#>100 Then gamespeed#=100

For a.ammo=Each ammo
TranslateEntity a\entity,0,-.75,0
If EntityDistance(a\entity,feet)<=7 Then clipammo=clipammo+50:a\alpha#=0
If a\alpha#<=0 Then FreeEntity a\entity:Delete a
Next


;update files
Gosub playerupdate
Gosub update

UpdateWorld(1/gamespeed#)
RenderWorld
If EntityY(eyes)<=liquid# Then
alpha#=.25
EntityColor fade,32,175,223
capturescreen()
wobbleview()
EndIf

If KeyHit(12) Then savescreenshot()

If health>0 Then

Color 255,0,0
x=GraphicsWidth()/2
y=GraphicsHeight()/2
If MilliSecs()>tmrmouse+100*gamespeed# Then
tmrmouse=MilliSecs()
fmrmouse=(fmrmouse+1)Mod 15
EndIf
DrawImage reticle,x-13.5,y-13.5,fmrmouse

Color 57,203,219
Rect 120,25,armor*4,25,1
Color 233,65,60
Rect 120,25,health*4,15,1
Color 123,236,74
Rect 119,24,401,26,0

Color 175,175,75
Rect 10,15,16,202,0

Color 207,221,40
Rect 11,16,14,ammo*2,1


Color 255,255,255
Text 10,215,ammo
Text 10,230,clipammo

Text 0,0,(EntityY(eyes)/liquid#)


Text 0,10,MilliSecs()/1000

Text 0,20,fire

Else
HideEntity gun
HideEntity feet
EndIf

If alpha#>=1 Then
Text 320,240,"You Have Failed",1,1
EndIf

If alpha#>=2 Then End

Text 600,0,alpha#
Flip
Wend

health#=0

Gosub update

FreeBank info

Goto gameload

End

.playsetup
Include "subs\player.bb"
Return

.setup
Include "subs\types.bb"
Include "subs\sounds.bb"
Return

.playerupdate
Include "subs\player run.bb"
Return


.update
Include "subs\projectile.bb"
Include "subs\ai.bb"
Include "subs\bullets.bb"
Include "subs\effects.bb"
Return


Function computertype(word$,x#,y#,Dela#)
Locate x#,y#
For i=1 To Len(word$)
Write Mid$(word$,i,1)
Delay dela#
Next
End Function

Function capturescreen()
CopyRect 0,0,GraphicsWidth(),GraphicsHeight(),0,0,BackBuffer(),ImageBuffer(screenbk)
End Function

Function WobbleView()
gw#=GraphicsWidth()
gh#=GraphicsHeight()
underw_a=(underw_a+4)
steph#=gh/32
mu8#=gh/60
If underw_a>359 Then underw_a=0
For iif#=0 To gh-4 Step .001
wsin#=(Sin((underw_a+iif)Mod 360.0)*mu8#)
CopyRect 0, iif, gw,steph+4, 0,iif+wsin#, ImageBuffer(screenbk),BackBuffer()
iif=iif+steph
Next
End Function

Function LoadSkyBox( file$ )
m=CreateMesh()
;front face
b=LoadBrush( file$+"_FR.bmp",49 )
s=CreateSurface( m,b )
AddVertex s,-1,+1,-1,0,0:AddVertex s,+1,+1,-1,1,0
AddVertex s,+1,-1,-1,1,1:AddVertex s,-1,-1,-1,0,1
AddTriangle s,0,1,2:AddTriangle s,0,2,3
FreeBrush b
;right face
b=LoadBrush( file$+"_LF.bmp",49 )
s=CreateSurface( m,b )
AddVertex s,+1,+1,-1,0,0:AddVertex s,+1,+1,+1,1,0
AddVertex s,+1,-1,+1,1,1:AddVertex s,+1,-1,-1,0,1
AddTriangle s,0,1,2:AddTriangle s,0,2,3
FreeBrush b
;back face
b=LoadBrush( file$+"_BK.bmp",49 )
s=CreateSurface( m,b )
AddVertex s,+1,+1,+1,0,0:AddVertex s,-1,+1,+1,1,0
AddVertex s,-1,-1,+1,1,1:AddVertex s,+1,-1,+1,0,1
AddTriangle s,0,1,2:AddTriangle s,0,2,3
FreeBrush b
;left face
b=LoadBrush( file$+"_RT.bmp",49 )
s=CreateSurface( m,b )
AddVertex s,-1,+1,+1,0,0:AddVertex s,-1,+1,-1,1,0
AddVertex s,-1,-1,-1,1,1:AddVertex s,-1,-1,+1,0,1
AddTriangle s,0,1,2:AddTriangle s,0,2,3
FreeBrush b
;top face
b=LoadBrush( file$+"_UP.bmp",49 )
s=CreateSurface( m,b )
AddVertex s,-1,+1,+1,0,1:AddVertex s,+1,+1,+1,0,0
AddVertex s,+1,+1,-1,1,0:AddVertex s,-1,+1,-1,1,1
AddTriangle s,0,1,2:AddTriangle s,0,2,3
FreeBrush b
ScaleMesh m,500,500,500
FlipMesh m
EntityFX m,1
Return m
End Function

Function SaveScreenshot()

iFileNumber% = 0
Repeat
iFileNumber = iFileNumber + 1
sFileName$ = "Screenshot" + String$("0", 3 - Len(Str$(iFileNumber))) + iFileNumber + ".jpeg"
Until Not(FileType(sFileName))

SaveBuffer FrontBuffer(), sFileName

End Function


this is my main code loop, i have to errors but when I try to respawn, my guys stays in the same spot.


puki(Posted 2008) [#3]
I've not run this. However, considering you have walls in your code, bare in mind that collisions are stopping your 'guy' from moving - even if he is dead. You might need to reset your collisions.

Bare in mind I've not run your code, I just browsed it - but collisions are a common cause for this problem.


Matty(Posted 2008) [#4]
I don't think you understand how to use the 'include' command looking at your code.


Ben(t)(Posted 2008) [#5]
if you put include in a subroutine you can use it in more than one place. and to puki, when the player is placed at the top, he is hidden before any movement takes place. when I hit esc to respawn the player simply 'jumps' aprox. a foot in the air. you won't be able to run it because I can not supply the files online


Ben(t)(Posted 2008) [#6]
I think the problem is with the read file my program does not seem to read the file again is there something I'm not getting about readfile?


Ross C(Posted 2008) [#7]
There's no point in calling your include files every loop. Include takes blitz code saved in the include file and drops it right where the include command is at. This happens at complie time. Blitz will include these files regards of whether you put a condition against them.

As for your code, it might be easier to spot the errors if you indent your code at loops and IF THEN conditions etc etc.

It's hard to dry run in your head the code if it's that big, so you'll need to provide the media to go along with this so we can run it.


Ben(t)(Posted 2008) [#8]
I dont have anywhere to post the files


Ross C(Posted 2008) [#9]
email me a zip file of all the files and i'll try and see if i can sort it.


Ben(t)(Posted 2008) [#10]
okay


Ben(t)(Posted 2008) [#11]
I can't my zip file is 50 Mb and my e-mails allows only 10 Mb


Ben(t)(Posted 2008) [#12]
I guess my question is can a data file be read more that once in a program?


Ben(t)(Posted 2008) [#13]
never mind I fixed it, it was this issue

this line right here, I never told the program to reset unit$ so it ignored the load program after it had gone through once
While unit$<>"end"


sorry for wasting your time guys, I feel really stupid now.


Matty(Posted 2008) [#14]
You're not wasting our time - if people felt their time was being wasted they wouldn't bother replying at all.