Variable replacement

Discussion and feedback on Construct 2

Post » Wed Mar 12, 2014 6:44 pm

Hello I would have a feature request.

I spent about 1-2 hours today by replacing variables in complex blocks of code by new variable types.

Example:

x0+x1+x2+x3... (setting up huge blocks of code involving variables)

,,Oh wait, this does not work. I have to use a global variable. Or a local one instead. Or maybe better to use an instance variable. Oh noes I have to change hundreds of lines of code which contained the old variables. D:"

This was the scenario I had about 2 times today. It would be really usefull if construct had a feature which would allow the user to replace a variable and all it's references with a new one. Or a feature to find and replace specific peaces of code in an event sheet.
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Wed Mar 12, 2014 7:35 pm

Alyra Games wrote:Hello I would have a feature request.

I spent about 1-2 hours today by replacing variables in complex blocks of code by new variable types.

Example:

x0+x1+x2+x3... (setting up huge blocks of code involving variables)

,,Oh wait, this does not work. I have to use a global variable. Or a local one instead. Or maybe better to use an instance variable. Oh noes I have to change hundreds of lines of code which contained the old variables. D:"

This was the scenario I had about 2 times today. It would be really usefull if construct had a feature which would allow the user to replace a variable and all it's references with a new one. Or a feature to find and replace specific peaces of code in an event sheet.


I suggest you organize your code to have an easier time editing this.

Also global variables are really something to use only when needed, I'll always try to have a local static variable or instances variable first.

Also if you have complex calculation, I'd recommand using functions so the calcul is written once on the entire project, but called multiple times (so you only have to edit once), It'll also be easier to read.

(For your suggestion to find and replace, there is a research function for the events sheet, but I think it is for non-free versions only)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Mar 12, 2014 7:53 pm

I know how to use variables, but thanks.^^

The huge block of code already was in a (complex) function. I first used local variables to safe ram but then realised, that I needed global variables instead. Because no other event could acces that variables. It was a careless mistake but this can happen if you are not an experienced programmer. And this is constructs target group.

So it was just a suggestion as it would sometimes make things easier, if you make a mistake.
Last edited by Alyra Games on Wed Mar 12, 2014 7:54 pm, edited 1 time in total.
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Wed Mar 12, 2014 7:54 pm

Alyra Games wrote:I know how to use variables, but thanks.^^

It was just an example. The huge block of code already was in a (complex) function. I first used local variables to safe ram but then realised, that I needed global variables instead. Because no other event could acces that variables. It was a careless mistake but this can happen if you are not an experienced programmer. And this is constructs target group.

So it was just a suggestion as it would sometimes make things easier, if you make a mistake.


You should be able to drag them out of the function I think
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Mar 12, 2014 7:56 pm

This is true but it would have deleted all code which has this variables as references (so the whole function). I had to manually change each variable name to the new, global ones. x(
B
10
S
2
Posts: 135
Reputation: 1,090

Post » Wed Mar 12, 2014 8:07 pm

trust me, each variable likely consumes no more then a kilobyte of RAM
a typical computer/mobile device has at least a gigabyte of RAM.
B
9
S
3
G
1
Posts: 191
Reputation: 1,725

Post » Wed Mar 12, 2014 8:11 pm

In some cases It wouldn't have, like this one:

Image
Image

I just dragged otherValue outside, and everything stayed, because the expression still works
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Mar 12, 2014 8:17 pm

@ryackov

I trust you. :D


@Aphrodite
Thank you for trying it out. But this was not exactly what I had to do. I had to completely delete the local number (in your case) "value" and replace all parts where it had been with the new variable. In your case "otherValue". The same procedure for all 10 variables. :D

Oh... I think I now got what you did... . You just dragged the variable out of the group and it automatically changed to a global variable? oO
B
10
S
2
Posts: 135
Reputation: 1,090


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 5 guests