Sign In Register

How can we help you today?

Start a new topic

Defines like in c#


in many cases that would be great if we could use defines like in c# and other things like #if, #elif, #define. Because of this we could make that we could have different code for live and preview stages, this would also work in other cases. What do you think about this?

Hi Marcin,

You can check what stage you are current on in Cloud Code with "var stage = Spark.getConfig().getStage();" This will return either "live" or "preview", so you would be able to have specific code or modules set up to run after you have checked what stage you are on. Does that sound like it would work for you here ?



Sorry but thats not what I'm looking for because:
-here I can use simple "if"s instead of efficinent code cut by pre-compiling defines
-stage of game does not fulfill al lconditions which I would like to use. Lets say if I want to test performance of some things I could use define PROFILE_PERFORMANCE and everywhere where would be #if  PROFILE_PERFORMANCE special code would be enabled to check request times(etc.) only when I use this define. If I use "if"s the performance code always will be compiled and always "if" condition will be checked.
-also that kind of defines are great to make IDE to grayout not used code because of not matched defines, which also helps a lot
For sure you have used #definitions in C++/C#/other_languages and you can understand how much help they are :)


Hi Marcin,

Unfortunately we don't support precompiling definitions like in C#. The closest structure I can find in Javascript would be like this below:

var URL_KEY = function() { return 'CurrentURL'; } 

these constant structures could be stored in a module and used where needed through out the cloud code base. Hope this helps.


 - Steve

Unfortunately thats not what I expected. I hope that in future you will add that kind of #define feature :)



I realize this topic last had a response over seven months ago, but I wanted to chime in with information just in case it could be helpful: Defines are not possible with JavaScript. C# is compiled into a Common Language Runtime code. Because of this when you #define something, the CLR Compiler can check against the #defines and make the decision to skip over code. JavaScript is strictly interpreted. There is no compilation to be done, so your lines of code would be interpreted anyway.

What I've done in the past is added any directives I wish to use as variables at the top of my code:

var DEBUG = false;
var PROFILING = false;

Then later in my code I use plain old if statements to check for those variables. This has served me well enough in the past.

I realize this still does not solve your problem but this is the closest thing that will ever be possible to have unless JavaScript were to fundamentally change as a development platform, which seems unlikely given the age of the language.

Login to post a comment