Page 1 of 1

Structure Based Variables.

Posted: Wed Apr 14, 2004 12:13 am
by Shannara
Take a look at the following code:

Code: Select all

Structure MapRec
  Levels.l
  MaxX.l
  MaxY.l
EndStructure
MapHeader.MapRec ;The map header

MapHeader\Levels = 12
Returns following error:

This variable doesn't have a structure.

Now, even though that is not true (as it has a structure), it still errors out. I would love to see the ability to declare variables based on a structure in a future version of PB.

Posted: Wed Apr 14, 2004 12:36 am
by Kris_a
that is already possible. This code works fine for me! 8O

(Windows XP, PB 3.90)

Posted: Wed Apr 14, 2004 12:36 am
by Paul
???

Works fine here :?

How else do you think we fix the odd Windows API structures that is missing information? ;)

Posted: Wed Apr 14, 2004 12:53 am
by Shannara
Its not working in PB 3.90 for me. .. Oh nvm, I was trying to use the variable in a For....Next Loop... bleh, I gotta remember that the loops in PB are very restrictive ....any chance of using variables in the future with loops?

Posted: Wed Apr 14, 2004 1:25 am
by Kale
Oh nvm, I was trying to use the variable in a For....Next Loop... bleh
How about showing us code exactly the way your are using it? then we can see the real problem!

Posted: Wed Apr 14, 2004 1:41 am
by Shannara
mmhmm, turns it its not working.. lol following is the code....

Code: Select all

Structure MapRec
  Levels.l
  MaxX.l
  MaxY.l
EndStructure
MapHeader.MapRec ;The map header

  L.l
  X.l
  Y.l
  ML.l
  ML = MapHeader\Levels
  MX.l
  MX = MapHeader\MaxX
  MY.l
  MY = MapHeader\MaxY
  For L = 1 To ML
    For X = 1 To MX
      For Y = 1 To MY
        ;Empty Loop
      Next
    Next
Next

Posted: Wed Apr 14, 2004 1:44 am
by freak
Of course your code does nothing. All values are 0 because you never
assigned any numbers to them.

Timo

Posted: Wed Apr 14, 2004 2:01 am
by Shannara
I wonder why I didnt catch that... bleh, evil me :) this thread can be removed or moved, if someone wants to :)

Posted: Wed Apr 14, 2004 3:07 am
by Shannara
*sigh* It still gives the error message, Even with numbers assigned to them. I found a way around this (AFAIK) "bug". Declare the variable as an array, and it will run.

Can anybody move this back into the bugs section for Fred's attention?

Posted: Wed Apr 14, 2004 3:40 am
by Dare2
Heya Shannara,

I'm not sure it is a bug in PB. (But I am reading between the lines here..)

Are you wanting to have your structure move across a series of values?

If so, an array structure is needed. Or a block of memory that the structure record "floats" across, using memory addressing.

Posted: Wed Apr 14, 2004 4:06 am
by Shannara
I wanted one variable, defined as a structure. Such as MyVar.Structure.

Then access that variable's (structure) members where-ever.

Posted: Wed Apr 14, 2004 4:20 am
by AlGonzalez
:?: Not really sure what you're looking for, but here is your code with the values initialized and no error!

Code: Select all

Structure MapRec 
  Levels.l 
  MaxX.l 
  MaxY.l 
EndStructure 
MapHeader.MapRec ;The map header 

MapHeader\Levels = 2
MapHeader\MaxX = 3
MapHeader\MaxY = 3

ML.l = MapHeader\Levels 
MX.l = MapHeader\MaxX 
MY.l = MapHeader\MaxY 

If OpenConsole()    
  L.l : X.l : Y.l 
  PrintN("L,X,Y")
  PrintN("-----")
  For L = 1 To ML 
    For X = 1 To MX 
      For Y = 1 To MY 
        PrintN(Str(L)+","+Str(X)+","+Str(Y))
      Next Y
    Next X
  Next L
  
  Input()
  CloseConsole()
EndIf

End

Posted: Wed Apr 14, 2004 6:52 am
by Shannara
That seems to work for me. Hrm, I wonder why ah... cant assign constants to variables in structures can we? lol. Thats the only diff in code. hrm and them being in diff files.. argh, what a PITA.

I figured out the problem!! The variable must be declared as a global in order to be referenced in a procedure :) Thanks guys!