Structure Problem

Just starting out? Need help? Post your questions and find answers here.
RedmoonX
User
User
Posts: 26
Joined: Mon Jan 17, 2005 9:54 am
Location: Sweden
Contact:

Structure Problem

Post by RedmoonX »

Code: Select all

; this works

Structure my_struct
  my_x.l
  my_y.l
  my_sprite.l
EndStructure

my_pointer.my_struct

my_pointer\my_x = 2

Debug my_pointer\my_x

; this works not

Procedure function()
  Structure my_struct2
    my_x.l
    my_y.l
    my_sprite.l
  EndStructure
  my_pointer2.my_struct2
EndProcedure

Procedure set_value(val.l)
  my_pointer2\my_x = val
EndProcedure 

function()
set_val(2)

Debug my_pointer2\my_x

; ERROR: 
; line 27 this variable doesnt have a structure!
;
; whats wrong cant i use structures in procedures
is it not possible to have structures within procedures??

RedmoonX
^^
-
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

make the variable global.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Structure Problem

Post by traumatic »

that's no structure-problem: my_pointer2.my_struct2 is neither shared nor global...

EDIT: Damn, I'm always too late :evil:
Good programmers don't comment their code. It was hard to write, should be hard to read.
RedmoonX
User
User
Posts: 26
Joined: Mon Jan 17, 2005 9:54 am
Location: Sweden
Contact:

Post by RedmoonX »

lol :D

haha when i try to make "my_struct2" or "my_pointer2" global
then i get error

variable already decleared with another type: my_pinter 2

all i did was adding "global my_pointer 22 before procedure my_struct2()


plzz help

RedmoonX
^^
-
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Obviously you can't define the same structure twice...

do it EITHER this way:

Code: Select all

Structure my_struct2
  my_x.l
  my_y.l
  my_sprite.l
EndStructure

Global my_pointer2.my_struct2
OR this way:

Code: Select all

Procedure function()
  Structure my_struct2
    my_x.l
    my_y.l
    my_sprite.l
  EndStructure
  Shared my_pointer2.my_struct2
EndProcedure

Procedure set_value(val.l)
  Shared my_pointer2.my_struct2
  my_pointer2\my_x = val
EndProcedure
See?
Good programmers don't comment their code. It was hard to write, should be hard to read.
RedmoonX
User
User
Posts: 26
Joined: Mon Jan 17, 2005 9:54 am
Location: Sweden
Contact:

Post by RedmoonX »

thx.. the structures isnt the same
the first is "my_struct, my_pointer" the second is
"my_struct2, my_pointer2"

but now i now how to share the variables

thx

it worked

RedmoonX
^^
-
Post Reply