Structure Based Variables.

Just starting out? Need help? Post your questions and find answers here.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Structure Based Variables.

Post 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.
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post by Kris_a »

that is already possible. This code works fine for me! 8O

(Windows XP, PB 3.90)
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

???

Works fine here :?

How else do you think we fix the odd Windows API structures that is missing information? ;)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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?
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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!
--Kale

Image
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Of course your code does nothing. All values are 0 because you never
assigned any numbers to them.

Timo
quidquid Latine dictum sit altum videtur
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

I wonder why I didnt catch that... bleh, evil me :) this thread can be removed or moved, if someone wants to :)
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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?
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

I wanted one variable, defined as a structure. Such as MyVar.Structure.

Then access that variable's (structure) members where-ever.
AlGonzalez
User
User
Posts: 53
Joined: Sun Feb 15, 2004 6:04 am
Location: Easley, SC, USA

Post 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
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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!
Post Reply