What if you could replace variables like objects in events?

Discussion and feedback on Construct 2

Post » Mon Dec 28, 2015 2:36 pm

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.
B
13
S
4
Posts: 61
Reputation: 1,028

Post » Mon Dec 28, 2015 3:23 pm

Yep that would be great. Im all for it too.
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Mon Dec 28, 2015 11:17 pm

Yep that would be of great help.
B
13
S
4
G
1
Posts: 18
Reputation: 1,081

Post » Tue Dec 29, 2015 1:51 am

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.
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Tue Dec 29, 2015 2:15 am

I don't know if that would be possible but that would be nice!
B
86
S
25
G
11
Posts: 652
Reputation: 11,045

Post » Tue Dec 29, 2015 5:15 am

Solomon wrote: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.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue Dec 29, 2015 5:29 am

@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.
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Tue Dec 29, 2015 6:06 pm

@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.
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Post » Tue Dec 29, 2015 7:35 pm

@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 8-)
Brick by brick, stone by stone.
B
52
S
24
G
17
Posts: 273
Reputation: 12,663

Post » Tue Dec 29, 2015 10:46 pm

@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 :)
Image
B
33
S
11
G
2
Posts: 563
Reputation: 5,141

Next

Return to Construct 2 General

Who is online

Users browsing this forum: Brendan2007 and 5 guests