Main Menu

data

Started by RaverDave, March 30, 2008, 01:19:08 AM

Previous topic - Next topic

RaverDave

hmm,a problem..as i know it data statements work like this..
PlayBASIC Code: [Select]
restore dt1
for n=1 to 3
p=readdata()
next

restore dd2
for n=1 to 4
o=readdata()
next
dt1:
data 1,1,1
dt2:
data 2,2,2,2



a small example but this should be all good,however i have used the same thing, just on a grander scale,it does the 1st bit of data ok, but the 2nd bit isnt ok,I dont get errors, just unexpected values!Its hard to explain but i guess i could paste the code if need be
i am making sure i use restore <label> each time

kevin

#1
 Without the whole program how can anybody really tell ?  as the following returns 9

PlayBASIC Code: [Select]
   Global Count

invadersinit()

print Count

Sync
waitkey


Function invadersinit()
Restore wave
For x=1 To 9
i=ReadData()
If i=1
count=count+1
EndIf
adder=adder+30
Next
EndFunction

wave:
Data 1,1,1,1,1,1,1,1,1




Draco9898

works fine for me

global count

type Tinvaders
xpos,ypos,framestart
endtype
dim invaders(20) as Tinvaders

invadersinit()
text 10,10,count
sync
waitkey
end

Function invadersinit()
Restore wave
For x=1 To 9
i=ReadData()
If i=1
count=count+1
invaders(x).xpos=x+adder
invaders(x).ypos=0
invaders(x).framestart=1
EndIf
adder=adder+30
Next


EndFunction
wave:
Data 1,1,1,1,1,1,1,1,1
DualCore Intel Core 2 processor @ 2.3 ghz, Geforce 8600 GT (latest forceware drivers), 2 gigs of ram, WIN XP home edition sp2, FireFox 2.

"You'll no doubt be horrified to discover that PlayBasic is a Programming Language." -Kevin

RaverDave

ok sorry..i think it was too much data in some other block before
damn me

RaverDave

no seriously sorry about that,i have been up all night,my kids seem to have a virus that makes em cough and puke all night(fun i know)!
here is the full proggy

; PROJECT : invaders
; AUTHOR  : RaverDave
; CREATED : 30/03/2008
; EDITED  : 30/03/2008
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
ScreenVsync On
Mouse Off
Global gw=28
Global gh=28
Global invader=1
Global invnum=50
Global count=0
Type tinvader
xpos
ypos
framestart
frameend
EndType
Dim invaders(invnum) As tinvader
makegfx()
invadersinit()
Repeat

For n=1 To 9
DrawImage invader,invaders(n).xpos,invaders(n).ypos,True
Next
Text 0,200,count
Sync

Until quit=True

Function invadersinit()
Restore wave
For x=1 To 9
i=ReadData()
If i=1
count=count+1
invaders(x).xpos=x+adder
invaders(x).ypos=0
invaders(x).framestart=1
EndIf
adder=adder+30
Next


EndFunction


Function makegfx()
CreateImage invader,15,15
RenderToImage invader
for x=1 to 14
for y=1 to 14
p=readdata()
if p>0
dot x,y
endif
next
next
  ScaleImage invader,30,30,2
RenderToScreen
EndFunction
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1

wave:
Data 1,1,1,1,1,1,1,1,1


As you can see i sometimes bite off more than i can chew at this ungodly hour!

RaverDave

#5
in fact i cant even recreate the event now..hehe!couldnt of been extra data in the first block because using restore <whatever>: forces it to read from that label onwards,which i knew was the fact! ah well!
I should really give up this programming lark and change my hobbies

RaverDave

#6
actually no. i have recreated what was puzzling me again, before i had the shape of an invader within the 1st block of data, but when i re-did it like above i had just a white block! Now this code doesnt work:


; PROJECT : invaders
; AUTHOR  : RaverDave
; CREATED : 30/03/2008
; EDITED  : 30/03/2008
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
ScreenVsync On
Mouse Off
Global gw=28
Global gh=28
Global invader=1
Global invnum=50
Global count=0
Type tinvader
xpos
ypos
framestart
frameend
EndType
Dim invaders(invnum) As tinvader
makegfx()
invadersinit()
Repeat

For n=1 To 9
DrawImage invader,invaders(n).xpos,invaders(n).ypos,True
Next
Text 0,200,count
Sync

Until quit=True

Function invadersinit()
Restore wave
For x=1 To 9
i=ReadData()
If i=1
count=count+1
invaders(x).xpos=x+adder
invaders(x).ypos=0
invaders(x).framestart=1
EndIf
adder=adder+30
Next


EndFunction


Function makegfx()
CreateImage invader,15,15
RenderToImage invader
restore invi
for y=1 to 14
for x=1 to 14
p=readdata()
if p>0
dot x,y
endif
next
next
  ScaleImage invader,30,30,2
RenderToScreen
EndFunction
invi:
data 0,0,0,0,0,0,1,1,1,1,1,1,1,1
data 0,0,0,0,0,1,1,1,1,1,1,1,1,1
data 0,0,0,0,1,1,1,1,1,1,1,1,1,1
data 0,0,0,1,1,1,1,1,1,1,1,1,1,1
data 0,0,1,1,1,1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1

wave:
Data 1,1,1,1,1,1,1,1,1

all thats happened as you can see is that i have changed a few 1's to 0's, to indicate i dont want a pixel drawing onto the image buffer there

kevin

#7
  If you use restore to change the Data pointer, then the label needs to be local as well, otherwsie it won't be able to find the it.  So if use Restore Label inside a function and the label isn't locally declared inside the function, then parser will assume you want to use the param as integer / string variable.  

 If it's integer then it'll use this variables current value (of zero) as the data pointer

 If it's string, it'll search for the this tag in the data heap.  

 Using a string tags is generaly the best approach, this lets you write more dynamic code than using labels.   Ie.  


PlayBASIC Code: [Select]
; PROJECT : invaders
; AUTHOR : RaverDave
; CREATED : 30/03/2008
; EDITED : 30/03/2008
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
ScreenVsync On
Mouse Off
Global gw=28
Global gh=28
Global invader=1
Global invnum=50
;Global count=0 ; This shouldn;t be global


Type tinvader
xpos
ypos
framestart
frameend
EndType

Dim invaders(invnum) As tinvader
makegfx()

; return the count from the init function call
Count=invadersinit()

Repeat

For n=1 To 9
DrawImage invader,invaders(n).xpos,invaders(n).ypos,True
Next
Text 0,200,count
Sync
Until quit=True


END


Function invadersinit()
restore FindData( "wave:",0,0)+1
For x=1 To 9
i=ReadData()
If i=1
Count=Count+1
invaders(x).xpos=x+adder
invaders(x).ypos=0
invaders(x).framestart=1
EndIf
adder=adder+30
Next
EndFunction Count


Function makegfx()
CreateImage invader,15,15
RenderToImage invader
restore FindData( "invi:",0,0)+1
for y=1 to 14
for x=1 to 14
p=readdata()
if p>0
dot x,y
endif
next
next
ScaleImage invader,30,30,2
RenderToScreen
EndFunction




Data "invi:"
data 0,0,0,0,0,0,1,1,1,1,1,1,1,1
data 0,0,0,0,0,1,1,1,1,1,1,1,1,1
data 0,0,0,0,1,1,1,1,1,1,1,1,1,1
data 0,0,0,1,1,1,1,1,1,1,1,1,1,1
data 0,0,1,1,1,1,1,1,1,1,1,1,1,1
data 0,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1
data 1,1,1,1,1,1,1,1,1,1,1,1,1,1

Data "wave:"
Data 1,1,1,1,1,1,1,1,1






RaverDave

#8
damn sorry i didnt see the reply!thankyou,i thought i was going mad!! i knew something was amiss,of course in any other language it wouldve been!