What if you could replace variables like objects in events?

0 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • In the event sheet I use replace object quite a lot. I think it would speed up workflow if you could select a group of events and replace all references to a variable to another variable. This would save having to go scrolling through a pull down over and over. I have lots of variables and it's getting pretty brutal.

  • Yep that would be great. Im all for it too.

  • Yep that would be of great help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That and an option to filter variables by event sheet while picking them, sort of a folder category.

    So if you have 3 event sheets with variables, and they are to run together, when picking variables you can toggle tick which to view.

    That would help with searching through the gazillon variables.

  • I don't know if that would be possible but that would be nice!

  • That and an option to filter variables by event sheet while picking them, sort of a folder category.

    So if you have 3 event sheets with variables, and they are to run together, when picking variables you can toggle tick which to view.

    That would help with searching through the gazillon variables.

    I'd get behind this too.

    Its because of this I don't use global variables. at all. I use some local variables but mostly I create objects with variables on them. I've even considered making an empty plugin except for variable stuff.

  • Ruskul

    No global variables eh? I guess you use functions instead too where possible. I have a weakness for variables both global and local, less for instance global variables as these are hidden and I need to keep refreshing my mind regarding their names.

  • Solomon - I create objects solely to house certain variables. I'll use local variables if need be, but generally I orginize according to purpose and name the objects so that it makes sense. For example, I always have an object called level. When I want to know something about the current level, I just say level.something = whatever. I follow this format for all my global variables. In this way I find that, though I do forget their names, they are not cluttering up my expressions list and whatnot. I can't stand trying to find a variable because I don't know its name and having to sift through hundreds of others. So long as I remember what the variable is used for (which hopefully I do as I am about to use it) I can then locate the object that it is tied to.

    Common objects I use to house variables : CharacterLaws, CharacterAttributes, Level, Global, Input, and so on. Sometimes I use cmv and read those for attributes and laws(or constants as most call them - Constants that govern my game universe I usually call laws)

    As far as functions go I usually don't overuse them. I like dynamic systems but it really eats at performance in a big game unfortunately. Instead, I like to script recuring events out into behaviors. I then gain a performance boost by bypassing the event sheet which has its own overhead. In the end I can have a complex set of scripts and only a hundred or so actions tying them all together. They are not usually versatile, but thats not the point lol.

    At the end of the day I would love to use gloabl variables... but they need to be able to be organized and accessed via name.name.

    As it is I even name every variable in the game, local or otherwise, vSomething that way I can always find them in one spot in the expressions when they come up. You just type v and then you can see all the variables.

  • Ruskul

    Hey some great information here and informative insight. I dont mean to derail the thread (anyway I think most have been said regarding additional visual options concerning variables) but I was wondering if you could elaborate on some of your points. I hope you dont mind if I pick your brain a little bit.

    How is it that you turn events into behaviours (if I understood correctly)? That is a great idea, to create a set of events, get them into an behaviour and use them by just adding a behaviour to your desired object (sort of an external limited function).

    Is there an easy way to this or is it done, from what I know, using java?

    Functions use up more memory than using variable based loops? Is this true for PC/Mac as well as it is for mobile export? So are you suggesting to stay away from functions as a whole, or to limit their implemetnation? I thought functions help stop code repetition and thus increase performance by decreasing the amount of code that had to be processed? Or was that mainly for the programers sake, as repeating code is not needed only running a function, which can be compared to a shortcut on a computer desktop instead of searching for the program in folders by hand.

    Regarding the objects and instance variables, do you use empty sprites or just rectangles? Do the additional sprites not weigh more than global varaibles in the event sheets?

    Regarding naming conventions, I see that quite often not only in programming. For example in rigging programs the name bones, dummies, props accordingly altough these can be toggled by type anyway.

    Last but not least what does "cmv" stand for, as I guess you are not referring to a virus that pops up with a web search lol.

    Thanks for your time and insight.

    Ps. Congrats on implementing slopes in your game, if that is easy I dont know what is hard for you

  • Solomon - I don't mind at all!

    1.) Behaviors...

    I use javascript to create behaviors. If I do something, like math, or really any set of isolated events I often create a small behavior that does the same thing. It helps keep my event sheet clean and tidy. The downside is that creating a behavior takes alot longer than creating events because you have to connect it all up so you have conditions, actions, etc. If you want the behavior to save its state then there is all that work too.

    Here is a case example: In my game I have a boomerang. The math that controls the boomerang is the same every tick (if a boomerang exists) so instead of using events to control it I created a small behavior that has 2 actions: "SetTarget", and "Update". If you hard code the constants, writing the bahvior is quick and easy, but if you think you will need it again for other things its best to expose those constants as variable parameters exposed to construct. In general, if I spend an hour prototyping an event based behavior, I can get it set up as a behavior in 10-20 minutes depending.

    If the behavior is more of a object relationship behavior, things get a little more difficult, but in the sdk you can have two behaviors talk to each other... The problem is that they become dependent and only work if you have both behaviors. Typically I don't let behaviors do anything without me telling them to do so via an action. I even have split out the everytick auto update that occurs in platformer and created an action "Update". In this way I can control when an object gets updated, if at all.

    Events that are purely math or similar are most like you said, "an external function". I would do this for things like quadratic lerp, Threshold translations, and other things. If a function made via events does not refer to specific objects, I most definitely add it to a custom plugin that houses all my functions for a particular game. This ties in a bit with what I mentioned about event functions which I'll get to in a moment.

    I hope this all makes sense!

    2.) functions.

    I keep my event functions to a minimum for a few reasons, though in the past I used hundreds of dynamic functions. I would have functions calling functions and objects updating by calling a function name that was stored in a variable. There is neat stuff you can do around that kind of orginization but there are some problems with that in construct.

    Firstly, there is an overhead performance hit to every condition and action you do. If you make an event sheet to do the same thing a behavior does, the behavior will run much much faster. For some games this is irrelevant, but for others it can be important. If you create a nested loop in construct that doesn't do anything (100 x 100) it will make a noticeable hit on your performance. (basically thats 10000 conditions, or however you want to think about it). If you do the same thing in a javascript behavior you will hardly notice it running (assuming its doing nothing as well). The result of the putting that in a behavior is that the event sheet only does 1 thing and thats call the "update" action on the behavior, then the behavior does the rest at a much better performance. The event sheet is great, but it is also incorporates a super powerful object picking system that has its costs.

    Function within construct make that system do more work. The time it take to call a function is 5 times what it takes to perform a simple variable = x action or condition. If you function has many actions then it is probably worth it... but if you call a function to only do 1 or 2 things and then that calls another function to do a few things and then this function needs a parameter passed to it with an object uid and then you have to pick that object again... This can all add up if you are doing this 1000 times a tick.

    Functions are only for the benefit of the programmer. A computer is so fast that it makes sense to use them. But in the case of construct 2 you are using a virtual function system that is built ontop of javascript. The performance loss here is not trivial if you have many objects. There is a forum post that I started a month or so ago where ashley talks about this. In most cases you needn't worry about using functions, but in my case, and in my particular game, I was using functions like I would be if I were writing in c++ creating a very object oriented dynamic event system. This was okay until I wanted 100 baddies on screen at once. My performance bottleneck was function calling. Even in c++ there is a performance hit for using functions, its just much more trivial. But when you use a function in construct you are basically emulating a function. Its a very high level language, so to speak, built on a high language.

    This is true for any export platform. For my game, I basically stripped out the functions and put them in behaviors. It allowed me to up my object count and still stay within a performance goal.

    ....

    I'm going to go ahaead and post this and then answer the rest of your questions in another post. 1 sec

  • Solomon -

    "Regarding the objects and instance variables, do you use empty sprites or just rectangles? Do the additional sprites not weigh more than global varaibles in the event sheets?"

    What do you mean by weigh more? Are we talking performance or just in terms of finding them in the expressions list? In many cases I actually waste the time to make nice graphics for my variable objects. The player never sees them, but a meaningful image helps me see whats going on when I look at the event sheet. Like I have a little world icon for my global variables object and a picture of a generic level for my level object, a controler for my input object and so on. The pictures next to the object in the event sheet are one of the biggest reason I love using construct lol.

    CMV stands for comma exasperated values. I think it was Colludiom, or R0j0hound that got me using those. They can be quite useful if you have a very data heavy game. You have to use ajax and read in the files but you can use it to change the game parameters in an excel spread sheet and can be handier than working with constructs variables. You still have to have the variables but when you create an enemy "troll" you could just set the common enemy variblels to teh trollLv 1 cmv and presto, less work on your end for the same effect as setting it all up manually in construct. If that makes sense.

    ---

    As for slopes in my game, did I mention that? Or is that from a different post lol. Slopes are a royal pain lol.

  • Ruskul

    Wow, thank you for your post, it is much appreciated! Very informative.

    Regarding behaviours and Javascript Ill have to pass on that one, at least for the time being. Altough from what you write it shows the power behind learning Javascript and using it in combination with C2, I want to stick to visual programming, at least for the moment, until I get a solid grasp on logic, at least in the form that is present in C2.

    On a side note Ive looked into various other programs and procrastinated some time in trying to pick the right software, but in the end you got to pick something and C2 seemed just more intuitive. In Unity Ive read for example, that making 2D games is hardcore, a few pages of code are needed just for some basic structure implementation. I would rather focus on the nicer side of gaming so to speak, since I am mainly into graphics and less into programing.

    It is good to know the downside of functions, and that will be the first place I look I have a performance bottleneck.

    As for 100 baddies, a the moment I have 50-something instances on the screen at once, and NWjs seems to cope quite fine, and that is baddies along with HUD elements. I am constantly using the debugger to check performance and hopefully I wont get nowhere near to a situation where I have to decide on performance vs content, at least not too soon anyway, because it is meant to happen sooner or later (this is regarding a PC/Mac game).

    By saying that sprites weigh more, I meant as they are sprites they are additional objects that have to be taken into consideration by the processing power. Do you use this method for mobile games as well, or mainly desktop content?

    I have to admit, your workflow is interesting at least to the extent to which my current level of understanding reaches.

    As for CMV I will need to look into those, especially if that is to speed up my work.

    Regarding slopes, I had a look at your profile and your entry on your web page, where you mentioned solving slopes being easy (as well as the other thread here on C2).

    Oh one more thing. Have you done or do you know someone that has created a game in C2 that weighed more than 600mb? Do you know how C2 handles such big files when exporting to NWjs? I created a thread earlier and recieved no response, just thought I take this opportunity and ask you as you sound quite proficient in what you do, and perphaps your experience might venture into this matter

    Once again thank you for your time!

  • Solomon - I'm sending you a pm, I didn't want to hijack the thread too much!

  • I think it would speed up workflow if you could select a group of events and replace all references to a variable to another variable.

    I'm not sure I understand why you would want to do this. If you want to change the name, you can rename it and all references update. If you want to change the type, you can't, because it would make events invalid. So then all there is left to do is to replace references to variable with references to another existing variable. Why would you want to do that? Presumably if you made two variables, it's for two different purposes, so I'm having a hard time imagining a useful example of wanting that.

    That and an option to filter variables by event sheet while picking them, sort of a folder category.

    So if you have 3 event sheets with variables, and they are to run together, when picking variables you can toggle tick which to view.

    That would help with searching through the gazillon variables.

    That is what local variables were specifically designed to do. Make them static and they work like global variables. Put them in a group or subevent and they are scoped to that level only.

  • [quote:nl2ou3wl]

    That and an option to filter variables by event sheet while picking them, sort of a folder category.

    So if you have 3 event sheets with variables, and they are to run together, when picking variables you can toggle tick which to view.

    That would help with searching through the gazillon variables.

    That is what local variables were specifically designed to do. Make them static and they work like global variables. Put them in a group or subevent and they are scoped to that level only.

    Ashley

    Yes, but that does not help in picking them out from a list of hundreds of variables. If only local variables could be chosen from a list where only local variables are present, that would be so much simpler.

    What I mean by this is the comfort of choosing from smaller lists. As of now it is starting to become a chore for me to add more variables and keep searching for the ones I want in a long list.

    To sum it up, local variables in a subfolder with only local variables, and global with only global. Additionally as I suggested, each event sheet with its own variables to form visually easier and quicker selection lists.

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