[Implemented] definition of global vars

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] definition of global vars

Post by BackupUser »

Restored from previous forum. Originally posted by alizta.

it would be nice to be able to declare vars like that

Global Newlist glFooVar.l



---when all you have is a hammer, everything starts to look like a nail... ---
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

Linked list variables and dimmed variables is always global..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by alizta.

uhm.... no.
you can make them global... but it is kind of akward.
like

Global MyList
NewList MyList.YO_LIST()


---when all you have is a hammer, everything starts to look like a nail... ---
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ebs.

Yes - both arrays and linked lists ARE ALWAYS GLOBAL. From the help file:

Arrays are always globally accessable in PureBasic. This means that they can always be accessed from inside procedures without needing to use the Global or Shared commands.

Lists are always globally accessable in PureBasic. This means that they can always be accessed from inside procedures without needing to use the Global or Shared commands.

Eric
Originally posted by alizta

uhm.... no.
you can make them global... but it is kind of akward.
like

Global MyList
NewList MyList.YO_LIST()


---when all you have is a hammer, everything starts to look like a nail... ---
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

> uhm.... no.

uhm.....yes!

You have to keep in mind that purebasic is a one-pass compiler so you must declare your lists and dimmed vars on top of your code or at least above the procedures that's gonna use them...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by alizta.

i even tried before i posted... strange... i must have done something wrong... but i always declare global vars at the top of my code, since i come from c.

sorry for the caused anoyance.

---when all you have is a hammer, everything starts to look like a nail... ---
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

> Global MyList
> NewList MyList.YO_LIST()

Variables and Linked Lists can have the same Name, because they are two different things.
So what you do here, is declare a Global LONG Variable and then a Linked List of YO_LIST Type(which is Global by design).

Timo
Post Reply