News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Need help with types, not producing the values I thought they would.

Started by SpellSword, September 03, 2007, 08:26:07 PM

Previous topic - Next topic

SpellSword

I'm trying to create a 10,10 array where each coordinate has 3 variables:
AT, ATC and the M() array itself as the 3rd.

My thinking or implementation is flawed. I've read the PB Help Types tutorial and still can't figure out what I'm missing.  ???

Why does the below code print:
2
588
2

Shouldn't it print:
2
5
0

Type MI
AT
ATC
EndType

DIM M(10,10) AS MI

M(5,5).ATC = 5
M(5,5) = 2
Print M(5,5)
Print M(5,5).ATC
Print M(5,5).AT
waitnokey
waitkey


And why does this code print:
25
0
0

Shouldn't it be:
25
5
0


Type MI
AT
ATC
EndType

DIM M(10,10) AS MI

M(5,5).ATC = 5
M(5,5) = 25
Print M(5,5)
Print M(5,5).ATC
Print M(5,5).AT
waitnokey
waitkey


This prints:
3
52
0

Type MI
AT
ATC
EndType

DIM M(10,10) AS MI

M(5,5).ATC = 52
M(5,5) =
Print M(5,5)
Print M(5,5).ATC
Print M(5,5).AT
waitnokey
waitkey


And this prints:
0
0
0

Type MI
AT
ATC
EndType

DIM M(10,10) AS MI

M(5,5).ATC = 52
M(5,5) = 0
Print M(5,5)
Print M(5,5).ATC
Print M(5,5).AT
waitnokey
waitkey


Any help at all would be appreciated, this is driving me crazy.
When I dream,
I carry a sword in one hand,
a gun in the other...

kevin

Quote
M(5,5) = 2

Here your writing into the array container directly..  This will delete whatever type was allocate at this position and use the 2 as a new memory allocation handle.





   Type tCord
      X,Y,Z
   EndType
   
   Dim grid(10,10) as tcord
   
   Grid(5,5).x =100
   Grid(5,5).y =200
   Grid(5,5).z =300

  print Grid(5,5).x
  print Grid(5,5).y
  print Grid(5,5).z
     

Sync
waitkey


SpellSword

Ah, I didn't realize the variable being held by the Array was the Type itself.
It seems obvious now that you've pointed it out. :-[

I'm just glad it was something easy for me to fix.

Thanks for the help.Error Missing Closing Square Bracket
When I dream,
I carry a sword in one hand,
a gun in the other...