Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globals in For Loops ( or other "blocks" ) #629

Open
GWRon opened this issue Jul 13, 2023 · 3 comments
Open

Globals in For Loops ( or other "blocks" ) #629

GWRon opened this issue Jul 13, 2023 · 3 comments

Comments

@GWRon
Copy link
Contributor

GWRon commented Jul 13, 2023

a user had an issue reported in discord. I extracted the original problem:

SuperStrict

Type TPlayer
    Field x:Int
End Type

Local list:TList = New TList()

For local o:object = EachIn list
    Global example1:TPlayer = New TPlayer
Next
print example1.x

I thought a global can be declared everywhere - but it seems it can't:
Output:

Compile Error: Identifier 'example1' not found.

Same also for While-loops and surely other "blocks". And also inside "if endif".

@GWRon GWRon changed the title Globals in For Loops are not global Globals in For Loops ( or other "blocks" ) Jul 13, 2023
@GWRon
Copy link
Contributor Author

GWRon commented Jul 13, 2023

I am not sure if BCC should error out if someone "defines" a global somewhere where others cannot reach it. Or maybe "warn" ?

@GWRon
Copy link
Contributor Author

GWRon commented Jul 13, 2023

Midimaster ammended that a global in a "block" exists for the whole lifetime of the block (eg loop)

For Local i:Int=0 To 9
    Global wert:Int=10
    wert=wert+1
    Print wert
Next

Maybe the documentation for "global" should reflect it ?
Something that tells that globals "stay forever" but are limited in their scope (you can only read them in that scope)

@davecamp
Copy link

davecamp commented Jul 13, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants