News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

restore problems

Started by monkeybot, January 27, 2014, 11:55:39 AM

Previous topic - Next topic

monkeybot

Hi Kevin,I am using restore with a label to set my data pointer but it is returning 0,i can find the data with findData() and set the restore point from there,so i assume there must be  something weird in my game logic somewhere messing things up,any ideas to steer me in the right direction?


Thanks.

This example works as expected but restore doesn't seem to work in my program!?!
PlayBASIC Code: [Select]
 restore test2
print readdata$()
sync
waitkey

test1:
data "a","b"


test2:
data "c","d"






This below listing doesn't work as expected when run with F6

PlayBASIC Code: [Select]
; PROJECT : cg3
; EDITED : 27/01/2014
; ---------------------------------------------------------------------
explicit on
type tdepths
x#,y#,x2#,y2#,height#
endtype
dim depths(10) as tdepths

type tcone
i#,x#,y#,xv#,yv#
endtype
dim cone(100) as tcone



global pos

type tcheckpoint
x#,y#,x2#,y2
info
endtype
dim checkpoint(20,10) as tcheckpoint; list
;level1
makecheckpoints()
makedepths()
#print "finddata for level3 "+str$(finddata("Level3",1,0))
waitkey
end



Function makecheckpoints()
checkpoint(0,0).x#= 1700
checkpoint(0,0).y#= 300
checkpoint(0,0).x2#= 1750
checkpoint(0,0).y2#= 1000
checkpoint(0,1).x#= 3490
checkpoint(0,1).y#= 1311
checkpoint(0,1).x2#= 4141
checkpoint(0,1).y2#= 1469
checkpoint(0,2).x#= 2993
checkpoint(0,2).y#= 2619
checkpoint(0,2).x2#= 3401
checkpoint(0,2).y2#= 3501

checkpoint(0,3).x#= 2379
checkpoint(0,3).y#= 1795
checkpoint(0,3).x2#= 3154
checkpoint(0,3).y2#= 1995
local q
restore level2

#print "level2 "+str$(GetDataPointer())
; pos=finDdata("level2",pos+2,0)
; #print "pos "+str$(pos)
; restore pos
; #print "level2"+" "+str$(GetDataPointer())
; #print readdata$()
; #break

for q=0 to 3

checkpoint(1,q).x#=readdata()
checkpoint(1,q).y#=readdata()
checkpoint(1,q).x2#=readdata()
checkpoint(1,q).y2#=readdata()
next



local q
restore level3:

#print "level3 "+str$(GetDataPointer())
for q=0 to 3

checkpoint(2,q).x#=readdata()
checkpoint(2,q).y#=readdata()
checkpoint(2,q).x2#=readdata()
checkpoint(2,q).y2#=readdata()
next



EndFunction






function makedepths()

restore ld:
#print "ld "+str$(GetDataPointer())
local q

for q=0 to 3
depths(q).x#=readdata()
depths(q).y#=readdata()
depths(q).x2#=readdata()
depths(q).y2#=readdata()
depths(q).height#=readdata()
next

depths(0).x#=2000
depths(0).y#=600
depths(0).x2#=2100
depths(0).y2#=700
depths(1).x#=2066
depths(1).y#=1601
depths(1).x2#=2431
depths(1).y2#=1985
endfunction





local q
global conei=0;loadnewfximage("cone.png")

restore cones
#print "Cones "+str$(GetDataPointer())
for q= 1 to 35
cone(q).x#=readdata()
cone(q).y#=readdata()
cone(q).i#=newsprite(cone(q).x#,cone(q).y#,conei)
spritedrawmode cone(q).i#,2
spritecollision cone(q).i#,1
SpriteCollisionMode cone(q).i#,2
SpriteCollisionRadius cone(q).i#,10
SpriteHandle cone(q).i#,-12.5,-12.5;-getimagewidth(cone(q).i#)/2,-getimageheight(cone(q).i#)/2
PositionSpritez cone(q).i#,50
next

cones:
data 1433,3221,1416,3207,1370,3180,1318,3142,1255,3091
data 1185,3053
data 1543,588,1524,610,1503,643,1473,681,1454,720
data 2203,674,2207,704,2207,750,2207,792,2207,831
data 2205,868,2200,902,2200,950,2597,785,2576,805
data 2564,848,2571,868,2613,905,2640,900,2673,853
data 2673,838,2666,791,2622,779,1632,3097,1433,3296
data 3892,2165,3605,2534,3955,2158,3580,2588




Login required to view complete source code




kevin


Labels aren't global.  So you can't use restore inside a one scope to point to another scope.   Just use text markers, Restore will the find them


Restore "Settings"



Data "Settings"
Data 1,2,3,4,45

Data "Scores"
data 10000,2000,3000


etc

monkeybot

#2
oh cool,thanks for that.

so i have to put  a readdata$() at the start of any data reads?

kevin

 restore will set the data pointer to that item,  i generally wrap such things..


PlayBASIC Code: [Select]
   SetData("Scores")
print ReadData()

Sync
waitkey



Data "Settings"
Data 1,2,3,4,45

Data "Scores"
data 10000,2000,3000


Psub SetData(Label$)
Restore FindData(Label$,0,0)+1
EndPsub




monkeybot