hide variables from sight

0 favourites
  • 14 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • how do I hide variables so that they would not be seen when I use the "compare variable" condition or "set variable to" action? For example, I created global variables for controls, you know, keyboard numbers, so that I could change the numbers themselves in the options, or upgrade checking variables. Right now, I am not working with them, so I'd like to hide them so that there would be no tons of all the variables I don't need now when I choose a variable to compare/change. HOW I DU DIS

  • I don't believe there is a way to do it. Might be a cool feature though.

  • Oh and,forgot to say, I don't want to use array positions as global variables. That's a whole Lotta trouble.

  • You can disable variables by moving them to an empty event sheet and then make sure that event sheet isn't 'included' on another event sheet. Sometimes I make an event sheet only for vars.

  • It's pretty standard system to show all variables available in the current scope. I'd recommend you start using more local and instance variables, I rarely use any global variables as it's generally bad practice :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah if you have problems like that use local variables instead of globals ...

  • But by disabling, you mean those variables won't basically work? Oh and Darklinki , I will find out what local variables are, thanks.

  • The Fabulous Manual: Variables

    I think this is really what you need, cause you see local variables only in their scope ;)

  • I think it could have been nice to have a button press when we are seeing all the available properties and variables when we have the drop-down list showing. i.e if I press shift while viewing it, only global variables are shown, or if I press ctrl, only instance variables are shown and if I press alt only properties are shown. etc.

  • vee41

    What's bad practice about it?

  • What's bad practice about it?

    You'll end up with massive amount of variables that you see all the time, instead of variables only being available in scope they are needed in. In general, using lots of global variables encourages coding style that gets messy quickly. That is how I was taught to program, avoiding global variables in situations when more efficient options are available. :)

    EDIT: Here is what I was talking about.. Some of those points are relevant for C2 as well.

  • spongehammer

    This is cause he know any language like php, java .... There are globals very unsafe. AND BAD !

    Here are a few reasons they you should them don?t use in any language:

    • Source code is easier to understand when the scope is limited to the used elements (Also in C2)
    • A global variable can be get or set anytime (Makes them unsafe)
    • You can easily forget to reset globals, this causes often to problems that are hard to find

    Here are a few why you shouldn?t use them in Javascript(Construct):

    • They are slower to access in Javascript than locals because Construct/Javascript needs to check every scope
    • They are often not declared near the point of use(hard to read code)
    • IE automatically defines a bunch of global variables this could cause problems
    • They persist for the life of the script
  • vee41

    Darklinki

    Ha thanks, never knew any of that <img src="smileys/smiley9.gif" border="0" align="middle" />

  • I agree with Vee41.

    As a general practice I use myself.

    * Each event sheet get's a Group labels after the event sheet.

    * any variables that I need in the event sheet get put into the group

    * all groups in the event sheet get put into the head group

    * any access to the variable from an external event-sheet will often use a Function.Call("eventgroup.get[VAR]").

    it's really really rare when I find the use of a true GLOBAL required. When I do it will often be a value like "DEBUG_MODE" and similar.

    otherwise I think Darklinki does a good job of explaining the why. However to expand on that.

    C2 uses a self closure. This enforces that it's impossible for the same var name at the room to conflict with any browser's own variable decleration. However the rest is right.

    mindandcode.com/quick-thoughts/why-global-variables-have-slow-performance-in-javascript

    unlike many other languages that use a model of variable to memory address; which is direct. All variables in JS are stored in a table. JS actually traverses the table every time you need to access the variable. As a general rule of thumb for JS. If you need to use a variable data more than twice in any function. Then store the data locally in the function. then use it.

    ie

    A = 24734

    function scope{

       print A + A * A / A

    }

    is bad do the fact A is used outside the scope and JS needs to traverse the data table where A is stored.

    where as

    function scope{

    var b = A;

    print b + b * b / b

    }

    is better because JS won't be traversing the variable scope table for very long. As b is the only variable and ensures quicker execution.

    honestly though the example is so simple it wouldn't matter. But it adds up in heavier math computation needing to be done much mroe often... like graphics :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)