(Richard Rae) #1

Can you create a singleton in Blox3?

(Leslie Young) #2

You can create a Global Blox Variable if you need a global reference to something.

It is not truly a Singleton since there is no checks to make sure a duplicate of the type is being created. Blox is not a programming language like C# or C++ and you should not think on those terms when using it.

Keep in mind that Blox was not developed as a C# (or other) Code Writing tool. The code generator is just a supporting thing and not the main idea behind Blox. It did not even have a code generator for a long time and was not developed to be a code writing tool. So do not expect to find concepts you are familiar with in C# in Blox, like delegates, singletons, static, class properties, etc.

… excuse me if I have been over explaining it again and you really was just wondering about keeping references in a “global scope”, I just need to make sure people reading this and trying to decide whether Blox is the tool for them understands what it is about, or not about.

(Richard Rae) #3

I understand about Globals,what I was trying to do was have music playing non stop while restarting a level.I used the don’t destroy onload command but two or more music’s play after the reload.I realise that I can put an empty level at the beginning of the game and use this command and the immediately load the game level that this would work.

(Leslie Young) #4

Are you loading the music player’s scene again at some point? This could cause the duplication.

What I would do is have a “startup” scene and put the music player object in there. It would be a scene which only gets loaded once and marks all its objects to not destroy. I like to put my EventSystem and AudioListener objects in there too.

Blox supports this scenario via its Game Systems. The cool thing is that if you mark it correctly Blox can auto-load this startup scene when you press play from any other scene since it knows it is an important scene which should be present during testing of other scenes.