News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

udt array access confusion.

Started by XDumbnBassX, September 08, 2008, 03:51:08 AM

Previous topic - Next topic

XDumbnBassX

Hey everyone, im working on porting a tetris clone i made from flash to playbasic (ofcourse). I made a user defined type with arrays in it, and i seem to be having problems getting the arrays to retain the information.

my udt is setup as follows:

Type piece
      x#
      y#
      dead#
      width#
      height#
      blockIDs#(10)
      blockCount#
endtype

i then make a big stack of 'pieces' via:
Dim pieces(300) as piece

and finally attempt to setup pieces(0).blockIDs#(0) from inside a function via
pieces(pieceID#).blockIDs#(0) = newBlock()

pieceID# is ofcourse working just fine, infact everything else about this 'piece' or pieces(0) is just fine, but pieces(0).blockIDs#(0) never retains any values.

(this is true for any member of pieces, so its not an issue with my member refrence (0,1,2,3...) and as i said all the other values are sticking just fine)

i know you guys ussually perfer a full source code dump, but its a pretty good amount of code, of which id hate for you all to have to dig through for something thats probably silly on my part.

thanks! and ill deffinatley be uploading the sourcecode for all to checkout and maybe even learn from (my universal piece rotating code is cool =P) when it works.

kevin

#1
 If you make assignments to nested arrays with types, then the two side have to be of the same data type..

PlayBASIC Code: [Select]
Type piece
x#
y#
dead#
width#
height#
blockIDs#(10)
blockCount#
endtype

;i then make a big stack of 'pieces' via:
Dim pieces(300) as piece


For Obj=0 to 300
for id=0 to 9
pieces(obj).blockids(lp)=1000.0+id
print pieces(obj).blockids(lp)
next
Sync
waitkey
next





2015 MODEDIT: This is actually obsolette.


XDumbnBassX

thank you for the quick reply =).

the function newBlock() returns a number or more specifically it returns pID# which should be the same type of data. (the function works and does return a number)

Function newBlock()
   inc pID#
   retNum# = pID#
   createsprite pID#
   spriteimage pID#, 2
   positionsprite pID#, 0, 0
EndFunction retNum#

kevin

 Why is pID# a float ?  It should be an integer

XDumbnBassX

ignorance is the best answer i can give you. i changed all the floats to integers and it works like a charm. my final question about it is, and this is just for the sake of learning. why did making everything integers fix the problem? before it was all floats (array of floats, data returned was floats, etc.) so the data should have fit and sat just fine (im assuming) but now that their all integers it works.

thanks so much for all the help, and fast responses by the way!

kevin


    It's impossible to say without seeing the full code, but i suspect you've got some miss matched variables data types.   PB is multi instance.  So the variables,

  I
  I#
  I$

  are  totally independent of one another.   If you drop or add the post fix, when accessing say I or I#, then you're reffering to two different variables..



   I = 27
   I# = 45

   print I
   print I#
   
   print I+I#
   
   Sync
   waitkey