This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Const and functions in global.gd

Vale-gitVale-git Posts: 167Member

Hi,

I saw different "tutorials" about singletons in godot but still are not clear.

Lets assume I have a script file global.gs imported as singleton with name global.

Where I have this constant:
const BAR = 1
and this function:
func foo():
print("ok")

question: how I can manage to use them in any other scripts like:

print(global.BAR)

global.foo()

Thank you.

Best Answer

  • Vale-gitVale-git Posts: 167
    Accepted Answer

    It is working now.
    Seems it didn't recognized the auto-loaded file in first place.
    I have no idea why.

Answers

  • Vale-gitVale-git Posts: 167Member

    global,gd*

  • Vale-gitVale-git Posts: 167Member

    It is possible a bug?
    my global.gd:

    extends Node
    var BAR = 1

    I call BAR with:

    print(str(global.BAR))
    with this error:


  • Vale-gitVale-git Posts: 167Member
    Accepted Answer

    It is working now.
    Seems it didn't recognized the auto-loaded file in first place.
    I have no idea why.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.